Displaying an image with EJS in node.js/express
You have to assign app.use( express.static( "public" ) );
on app.js then don't forget the / as root:
<img src="/images/logo.jpg" />
the images folder should be in public folder:
- public/
- images/
- logo.png
- app.js
Static files in Express must go inside the directory specified in your static
middleware. This is commonly ./public/
.
For example, in your server.js
you may have something like this:
app.use( express.static( "public" ) );
Each file inside this folder will be accessible from the root URL, so this will work:
<img src="logo.jpg" />