Display images in HTML + Nodejs
First, you have to set the public (folder) as static under server.js file
server.js
// configure our application
const Express = require('express');
const app = new Express();
.......
.......
app.use(Express.static(__dirname+'/public'));
.......
then your img source will be
<img class="logo" src="/images/Heading.png" alt="My_Logo">
and here the folders structure would be -
project(root folder) \ public \ images\ Heading.png
Thanks for your answers.I had tried using absolute path already with no luck. However one of my friend suggested as below:
<img class="logo" src="http://localhost:3000/images/Heading.png" alt="My_Logo">
and keep the Heading.png
file in public/images
directory.
Thanks all.