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!'));
Am I missing something obvious? I assume that the JavaScript code is not an issue, but more likely its a Windows vs Linux environment difference. If anyone has any thoughts on what might be the issue I would appreciate the help!
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.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Well now I feel silly. After hours of trying to narrow down the problem I finally found it! In case anyone else has a similar issue to me, this was how I fixed it. The whole problem was with the way I was with my FTP. I use WinSCP to upload files and it was defaulting to a ‘Text’ transfer mode instead of binary. So I had to re-upload my images with the correct transfer mode (binary, instead of text) and now they finally show up.