This guide explains how to fix the Node.js application error: “Cannot GET” URL. You may get an error when you try to use the Node.js application.

The main reason is that cPanel’s Node.js implementation manages Node.js applications using Phusion Passenger. Passenger generates the root path when you create an app in Node.js cPanel using the data entered in the Application URL text field.

For instance, if the text field for the application URL is set to “app1,” the root path for the app is “/app1” rather than “/”.

Let us learn how to fix the issue:

  1. Take in the application URL in your routes.
  2. Using Express, the very popular web application framework, the following code demonstrates how to accomplish this.
  3. Execute the following command; it essentially expects that “app1” be entered in the Application URL text field of the Node.js app.
    const express = require(‘express’);
    const app = express();
    app.get(‘/app1/’, function(req, res){
        res.send(“Hi from the root application URL”);
    });
    app.get(‘/app1/testing/’, function(req, res){
        res.send(“Hi from the ‘testing’ URL”);
    });
    app.listen(0, () => console.log(‘Application is running’));
  4. In the above code sample, there are two codes defined, /app1 and /app1/testing. If your domain name is xyz.com and you are using your web browser to view http://xyz.com/app1 or http://xyz.com/app1, you get the Cannot GET error message.
  5. Two codes, /app1 and /app1/testing, are defined in the code sample above. You see the Cannot GET error when trying to view http://xyz.com/app or http://xyz.com/app1 on your web browser if your domain name is xyz.com.

That is it! Hope you liked our article.

 

 

Tagged: