Im trying to deliver all images inside a assets folder using Node and Express.
Folder structure:
.
└── src/
├── assets/
│ ├── 01.webp
│ └── 02.jpg
└── components/
├── Gamegrid.js
└── testedir/
├── 01.webp
└── 02.jpg
The Gamegrid.js code:
function definirGrid(numeroDeCartas = 12){
console.log('hei')
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
const PORT = 3001;
app.use('/testedir', express.static('testedir'));
app.use(path.join(__dirname,'..','assets'), express.static('assets'));
app.get('/',(req, res)=>{
res.send('hello world');
});
app.get('/sobre',(req, res)=>{
res.send('página sobre');
});
app.listen(PORT, ()=>{
console.log('app listening on port',PORT)
})
}
definirGrid()
I’m able to access http://localhost:3001/testedir/02.jpg
but not http://localhost:3001/assets/02.jpg
.
How can I route for the ../assets
images?
2
Answers
maybe like this:
You can do it in the same way as you did with the testedir folder.
However, I would advise you, to create one public folder which may include all the other folders you want to serve in public.