Problem: Images show up as broken icons. The images work perfectly fine when run locally on my own (windows 10) desktop, but on the ubuntu server it doe snot seem to work right.
Things to Note:
Example Code With Same Problem: I recreated a simplified version of code that has the same issue as my bigger project. The folder structure for this test was as follows:
testServer └> node_modules └> favicon.ico └> pattern.png └> index.js
This code below works and you see a page with the ‘favicon.ico’ image on it:
const express = require('express'); const app = express(); app.get('/', (req, res) => res.sendFile(__dirname + '/favicon.ico')); app.listen(3000, () => console.log('Example app listening on port 3000!'));
However, changing the ‘favicon.ico’ image to the ‘pattern.png’ image from the same directory causes an issue. There is no ‘ERROR: no such file or directory’ message that shows up, it just goes to a similar page that you get from the code above. However, in place of where the ‘pattern.png’ should be, there is nothing but an empty space with a white box outline around it. So it knows that the file with that path exists, but it does not show it properly
This is the code that does not work correctly:
const express = require('express'); const app = express(); app.get('/', (req, res) => res.sendFile(__dirname + '/pattern.png')); app.listen(3000, () => console.log('Example app listening on port 3000!'));
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.