MeetJoeBlack
MeetJoeBlack

Reputation: 2924

node.js express static images serving

I need to include my static images at html page. So I do it like that:

app.use(express.static(path.join(__dirname, 'public')));

And put all my images inside public under '/images' folder. So then I call it like this:

<img src="images/image_1.jpg"/>

But my path when page loaded looks like:

http://localhost:3000/product/images/image_1.jpg

Why did page url path http://localhost:3000/product/ added before img src?

Upvotes: 0

Views: 1365

Answers (1)

adeneo
adeneo

Reputation: 318332

If you're already at http://localhost:3000/product clicking a link with the href images/image_1.jpg takes you to http://localhost:3000/product/images/image_1.jpg as the URL is relative.

You probably wanted to use absolute paths instead

<img src="/images/image_1.jpg" />

Upvotes: 2

Related Questions