When you’re trying to use Node.js application on nodejs hosting, you might get an error about the app being unable to “Get a URL.”
The main cause is, Node.js implementation in cPanel uses Phusion Passenger to manage Node.js applications. When you create an app in Node.js cPanel, Passenger uses the value in the Application URL text box for creating the root path.
For example, if the application URL text box is set to ‘myapp’ then the root path for the app is not “/”but “/myapp”.
In this article, we will get know how to resolve this error.
How to Resolve the Error, Node.js application error message: “Cannot Get” URL?
Firstly, to resolve the issue, you need to include the application URL in your routes. The below code explains how to do this process using the very popular Express web application framework.
Related: How To Install Node.js On cPanel Server Via WHM?
It basically assumes that the Application URL text box in the Node.js app is set to myapp.
const express = require('express'); const app = express();
app.get(‘/myapp/’, function(req, res){
res.send(“Hello from the root application URL”);
});
app.get(‘/myapp/test/’, function(req, res){
res.send(“Hello from the ‘test’ URL”); });
});
app.listen(0, () => console.log('Application is running'));
In the above code sample, there are two codes defined,/myapp and /myapp/test. If your domain name is abc.com and you are using your web browser to view http://abc.com/my app or http://abc.com/myapp, you get the Cannot GET error message.