node.js – Node Js Serving react js frontend In Production No Such File directory

If you’re getting the error:

Error: ENOENT: no such file or directory, stat ‘C:\Users\kullanıcı\Desktop\Node Js\24-Nasa-Project\server\public\index.html’

That means you don’t have a file at the path:

C:\Users\kullanıcı\Desktop\Node Js\24-Nasa-Project\server\public\index.html

Just looking at that path, I notice: Users\kullanıcı\Desktop … that looks like a path from your computer. But you’re saying this is on your server … does your server actually have that folder?

What could be going on is you could have hard-coded that path somewhere in your code during development, and then when you try to use it on your server, it fails because your server doesn’t have that path. It doesn’t seem possible from the code you provided, but could there be any other code you didn’t share?

Alternatively, I noticed you had:

res.sendFile(path.join(__dirname, '..', 'public', 'index.html'))

Why the '..'? It seems your server.js is in your server project root folder, so .. would mean one folder above that .. but the public folder is in the same directory as server.js.

Read more here: Source link