I'm having issues trying to serve static files with expressJS. I want to serve files from a folder, using virtual route.
My app architecture looks like this
├── app
| ├── assets
| └── data
| └── img
| └── cards
| └── * (un bunch of image files)
| └── index.js
| └── server.js
├── node_modules
├── package.json
├── package-lock.json
My index.js
const express = require('express');
const path = require('path');
const app = express();
//Serving images
app.use('resources/cards', express.static(path.join('assets/data/img/cards')));
app.get('/', function (req, res) {
res.send('Hello World');
});
module.exports = app;
My server.js
const app = require('./index');
const config = require('./config');
//Mysql connection
const mysql = require('mysql');
app.listen(config.express.port, function() {
console.log(`Running on ${config.express.ip}:${config.express.port}`);
});
const connection = mysql.createConnection({
host: config.mysql.host,
user: config.mysql.username,
password: config.mysql.password,
port: config.mysql.port,
database: config.mysql.database,
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function (err, rows, fields) {
if (err) throw err;
console.log(`The solution is ${rows[0].solution}`);
});
//connection.end();
I want to access my images through localhost:3000/resources/cards/image.png, for example, but still getting this Cannot GET /resources/cards