src path for Express apps
If you are using Node.js with Express framework, the other answers will not solve your problem.
As said in Express' official documentation:
To serve static files such as images, CSS files, and JavaScript files,
use the express.static built-in middleware function in Express.
So you have to declare the folder of your static files. If, for instance, your image is located in:
[project root]/assets/images/image.jpg
then you should include in your main javascript file (e.g. index.js or app.js):
app.use(express.static('assets'))
then your img tag would look like:
<img src="/images/image.jpg" alt="Alternative Text">
Again, the documentation says:
Express looks up the files relative to the static directory, so the
name of the static directory is not part of the URL.
Therefore, in this example you should omit "assets" in the src path, and also note the opening "/".
img
element, right-click on thesrc
and Open image in new tab to see the url that it's trying to get. You can also see it in the console and the network tab. – Contradictiontest.html
with only the 2img
tags inside (the relative and abs) and see if that works... Also, did you check other browsers? – Contradiction