r/programminghelp • • Dec 26 '18

NODE.JS Problem with accessing images

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.

If anyone has any suggestions to this please help. I don't even know what to write (new to node.js) so if you have a ready code -- I'll appreciate it.

0 Upvotes

6 comments sorted by

1

u/thisgameissoreal Dec 26 '18

Do you have any examples of how you're trying to access it that isn't working?

1

u/Martixell Dec 26 '18

app.get('/Pictures', function(req, res) {res.sendFile(__dirname + "/" + "water.jpeg");});

app.get('/script.js', function(req, res) {res.sendFile(__dirname + "/" + "script.js");});

this method worked for the HTML, CSS, and JS

1

u/YasZedOP Dec 26 '18

Not 100% sure, but... Where you have /Pictures, replace that with /water.jpeg And in the sendFile, try __dirname+”/”+ "Pictures + "/water.jpeg"

1

u/Martixell Dec 26 '18 edited Dec 26 '18

So my project looks like this:

  1. -Project

    1. -Pictures

      1. -water.jpeg

    2. -css -js -html -jquery

1

u/Martixell Dec 26 '18

I'll try this, it might work who knows.

1

u/Martixell Dec 26 '18

app.get('/water.jpeg', function (req, res) {
res.sendFile(__dirname + '/' + "Pictures" + '/' + "water.jpeg");
});

unfortunately this doesn't work, thanks for the help tho