When I run my Node.js app on localhost, I can access for example http://localhost:3000/css/dashboard.css
However, if I put a logo.png to the same directory and try http://localhost:3000/css/logo.png on my browser, I only get “Cannot GET /css/logo.png”. I tried with several browsers.
In my app, the only reference to this is: expressapp.use(express.static(__dirname + ‘/public’)); The files are in a public directory that is in the same directory with the main app. I am using Windows 10. The mentioned css file is much older than the png file, which I just added to the project.
I tried to google, but to no avail.
Advertisement
Answer
OK, I’ll move my comments into an answer here since it led to you finding the duplicate directory and we can wrap up this question…
What you describe should not be a problem so you’re probably working with an incorrect assumption. Let’s check a few things. The error says it is looking for /css/logo.png
so your file should be in public/css/logo.png
. Is that where it is?
Are you 100% sure, you’re looking at the actual public
directory that the server is using? A not so uncommon mistake is to be madly editing files in a directory only to find out that it’s a duplicate directory and is not the one the server is actually using.