1. Home
  2. Applications Management
  3. Node.js
  4. How to fix the Node.js error: “Cannot GET” URL

How to fix 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”.

You are receiving this because the Node.js implementation in cPanel uses Phusion Passenger to manage Node.js apps. When you create an application in the Node.js cPanel, too, Passenger uses the value in the Application URL text box to create the root path.

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 / is typically the root path.

This Knowledgebase article will cover how to resolve this error.

Struggling with Node.js troubleshooting? ChemiCloud is the hosting solution designed to save you time! 🤓 Check out our Node.js Hosting plans!

How to fix the error Node.js application error message: “Cannot GET” URL

You need to include the application URL in your routes to resolve this problem. The following code sample demonstrates how to do this using the popular Express web application framework. It assumes that the Application URL text box in the Node.js cPanel tool 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 code sample, two routes are defined, /myapp and /myapp/test. If your domain name is example.com, and you use your web browser to view http://example.com/myapp or http://example.com/myapp/test, the pages load as expected. However, if you visit any other URL under http://example.com/myapp, you receive the Cannot GET error message.

 

 

Updated on April 4, 2022
Was this article helpful?

Related Articles

Spring into Savings!
Up to 78% Off Hosting Plans + Free Migration!
👉 View Deals

Comments

  1. Does this supports post method?

    I am trying to build api to POST email.

  2. I have just done thesame thing and everything runs well on command line but when I try to access the listening port on chrome browser I only see “cannot GET/”

Leave a Comment