Cannot get image on localhost

22,675

Solution 1

YOu have to serve your static files from express:

try Adding this:

app.use(express.static('public'));

(public is the folder where your images and everything (assets) reside)

More infos here: http://expressjs.com/starter/static-files.html

Solution 2

You need to tell express from where should it serve static content.

app.use(express.static('/path/to/your/folder')).

Source: http://expressjs.com/starter/static-files.html

In production, it's a general convention to serve static files using nginx. Look it up.

Share:
22,675
Admin
Author by

Admin

Updated on September 18, 2020

Comments

  • Admin
    Admin over 3 years

    I am working on a Node.js Express project and have used Bootstrap carousal template in index.ejs page. The image tag is not working if I try to get the image saved inside the project under "views" folder.

     <img  class="img-circle" src= "/proj1.png"  />  
    

    The index.ejs file is also in "views" folder. The error is: GET http://localhost:3000/proj1.png 404 (Not Found). I have tried changing the relative path of the file also but it did not work.