1

I recently began building an app with node.js. After some time I wanted to move it onto my hosting account to really test it.

First I installed nodejs from source. Then I changed nothing to the code except for Database login. When I ran it, there were no error. Excitedly I tried it out. To my dismay, I got a 404 for every single route I had programed.

For example:

router.route('/new')
.post(function(req, res){
    //My Route Code
});

app.use('/api', router);

Then I go to:

mywebsite.com/api/new

This returns a 404 Not Found Error from my apache server.

I would also like to note that I am using I am using Shared Hosting, and I have also thoroughly tested my code offline on my test server.

How can I fix it so that my code actually routes my request?

2 Answers2

0

It seems that it's not a problem with your Node app but with your Apache configuration.

If it is Express that is giving you 404 then you should see a 404 response with this in the body as plain text:

Cannot GET /api/new

This is a standard Express message. If you don't see it then it is not Express that's giving you that answer but something else along the way - likely Apache.

Make sure that your Apache is correctly configured as a reverse proxy for that host name and port that you try to access from your browser, and that it passes the requests to the correct host and port where your Node app can be accessed.

See those tutorials:

rsp
  • 107,747
  • 29
  • 201
  • 177
  • No I get a 404 Not Found, not the standard Express error. Its not getting to express i dont think –  Mar 29 '17 at 19:00
0

sudo service apache2 remove
node app.js

If you need node on apache then see this documentation
Apache and Node.js on the Same Server

Community
  • 1
  • 1
Vinayk93
  • 353
  • 1
  • 6