Reputation:
I can't display image, image is in the same folder.
each user,i in users //users data loop
h2=user.name
.card
img(src='img_rr_01.jpg', alt='Avatar', style='width:100%') // Image
|
.container
h4
b=user.email
|
p=user.name
Upvotes: 1
Views: 1677
Reputation: 19
If you have something like below in app.js you can directly specify the folder in which you have stored the images.
app.use(express.static(path.join(__dirname, 'public')));
Upvotes: 0
Reputation: 2376
Express is not going to serve anything that you don't give permission to. You have to give permission by using express.static middleware.
To serve static files such as images, CSS files, and JavaScript files, use the express.static built-in middleware function in Express
For more details refer to https://expressjs.com/en/starter/static-files.html
Upvotes: 0
Reputation: 10083
Make sure you are specifying your public assets folder by mentioning something like this -
app.use(express.static(path.join(__dirname, "/../public")));
Then your static file's paths should normally be starting with /
and then follow the path as it is in your public folder. e.g. if your image is in public/images
folder, then update your src
to be /images/img_rr_01.jpg
.
Please note that you need not mention public
folder in your src.
Upvotes: 1