So in my project I have folder /Pictures and everything else is all over the project folder. My problem is that I can access all the CSS , JS, HTML, but it doesn't let me get this image folder as a source of the web app.
I tried this(doesn't work):
app.get('/water.jpeg', function (req, res) {
res.sendFile(__dirname + '/' + "Pictures" + '/' + "water.jpeg");
});
I want all my images from the /Pictures folder to be a source for my web app.
So in my project I have folder /Pictures and everything else is all over the project folder. My problem is that I can access all the CSS , JS, HTML, but it doesn't let me get this image folder as a source of the web app.
I tried this(doesn't work):
app.get('/water.jpeg', function (req, res) {
res.sendFile(__dirname + '/' + "Pictures" + '/' + "water.jpeg");
});
I want all my images from the /Pictures folder to be a source for my web app.
Share Improve this question asked Dec 26, 2018 at 20:22 Martin DavidovMartin Davidov 431 gold badge1 silver badge7 bronze badges 03 Answers
Reset to default 5if image uploads to '/uploads' folder then try like
app.use('/uploads', express.static(process.cwd() + '/uploads'))
__dirname gives you the directory name of entry point file. I don't know where is your entry point file in your application, but that's where you have to start.
By the way, I advise you to use the "join" function of the "path" module to concatenate the path so as it works on linux or window filesystem.
I found a solution by Quora here, thanks to everyone who helped :) : link