0

In node.js, I want to return a page, that has a relative link to an image path. In the server I have server.js and images.jpg in the same folder. I ran the server, and when I visit the server link, it returns this html

 <!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>

<body>
The content of the document......
<img src="images.jpg"/>
</body>

</html> 

But the image is not loading. How can I get the correct relative link?

Thanks

5
  • 1
    How do you serve static files? What do you get when you visit images.jpg directly in browser? Commented Aug 15, 2015 at 23:28
  • I dont know how to serve it, nothing happens when I visit localhost:41302/images.jpg. Commented Aug 15, 2015 at 23:29
  • 1
    Try this stackoverflow.com/questions/26013675/… Commented Aug 15, 2015 at 23:32
  • 1
    Putting this file in the same folder will not make it automagically served. Commented Aug 15, 2015 at 23:32
  • 2
    we need to see your code to know what's happening Commented Aug 15, 2015 at 23:48

1 Answer 1

0

Your node.js server does not serve ANY images or files by default (this may be different than some other web servers). If you want it to serve a URL that is images.jpg, then you need to create a route/handler in your http server so that when that image is requested, the appropriate image data is returned.

If you show us your server code and show us the code that serves this particular page (so we know what path will come with images.jpg) and explain where in your file system that image is located, we could advise how to modify your node.js server so that it will serve this image.

If using Express with node.js, you can serve static files on a particular path with one line of code, but we need the above info to know more explicitly what to recommend.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.