Search code examples
node.jsexpresspassengernamecheap

Namecheap shared hosting, Express.js, and app.get() gives "cannot GET /path" error


I am following the tutorial here: https://socket.io/get-started/chat/

The code works locally but when I upload/Install it to my Namecheap shared hosting server, I get this error displayed in my browser:

Cannot GET /PathToApp

I have isolated the problem to:

app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html"); });

since I have another app that works fine locally but won't work when uploaded to Namecheap.

Also, there are no entries in the passenger logs.

Is there a setting I should be changing to get this to work?


Solution

  • Apparently, I have to set it up as:

    app.get("/uriToApp", (req, res) => {
    res.sendFile(__dirname + "/index.html"); });
    

    for app.get() to work.

    This post helped: Phusion Passenger on cPanel (Apache) "Cannot GET" (Express); the same code works on localhost and Heroku