Fixing the Node.js error: “Cannot GET” URL

Sometimes when using Node.js for your application(s) you may receive an error about the app being unable to “GET a URL”.

This is because of how Passenger uses Application URLs in cPanel, which can be fixed by changing where they are set up in either Phusion or NPM config files as needed!

For example, if the Application URL text box is set to ‘mycoolapp’ then the root path for the application is not “/” but is actually “/mycoolapp”.

This behavior differs from most other web environments where /path typically denotes a directory and “index.js” file located within that directory.”
This Knowledgebase article will cover how to resolve this error. How does one fix node js app error message: ‘Cannot GET’ url?

To fix this error, you need to include the application URL in your routes. The following code sample demonstrates how to do so using popular Express web framework. It assumes that the Application text box in Node.js cPanel is set to mycoolapp:

const express = require('express');
const app = express();

app.get('/mycoolapp/', function(req, res){
res.send("Hello from the root application URL");
});

app.get('/mycoolapp/test/', function(req, res){
res.send("Hello from the 'test' URL");
});

app.listen(0, () => console.log('Application is running'));

In this demonstration, two routes are defined: /myapp and /myapp/test. If your domain name is examplesite.com, when you visit http://examplesite.com/myapp or http://examplesite.com/ my app test in a web browser the pages load as expected but if you visit any other URL under http://examplesite.com it gives Cannot GET error message.

We hope this tutorial helps you find the perfect solution. If your like our tutorials, definitely you’ll love our support. All VernalWeb hosting plans include 24/7 support from our amazing inhouse support staff. Check out our Nodejs Hosting plans and have your website migrated today!

  • Was this article Helpful ?
  • yes   no