Node.js application error message: "Cannot GET" URL
When running a Node.js application through the Node.js Selector in cPanel, you may encounter the error:
This means the application received a request for a URL path, but no route was defined to handle it.
Common Causes
Section titled “Common Causes”- Missing Route Definition → The requested URL path is not defined in your application code.
- Incorrect Startup File → The file specified in the Node.js Selector (e.g.,
app.jsorserver.js) does not contain the correct routing logic. - Wrong Application Root → Files are not located in the directory set as the application root.
- Port or Path Issues → The app is listening on a port or path that doesn’t match the request.
How to Fix
Section titled “How to Fix”1. Verify Routes
Section titled “1. Verify Routes”Make sure your application defines routes for the requested URL. Example using Express.js:
const express = require('express');const app = express();
app.get('/', (req, res) => { res.send('Hello World!');});
app.get('/myapp', (req, res) => { res.send('This is my app route.');});
app.listen(3000, () => { console.log('App running on port 3000');});If you visit /myapp, the app must have a corresponding app.get('/myapp', ...) route.
2. Check Startup File
Section titled “2. Check Startup File”- In cPanel → Setup Node.js App, confirm the Application Startup File points to the correct file (e.g.,
app.jsorserver.js). - Ensure this file contains the routing logic.
3. Confirm Application Root
Section titled “3. Confirm Application Root”- Verify that your app files are inside the directory specified as the Application Root in Node.js Selector.
- If files are in a subfolder, update the root path or move them accordingly.
4. Restart the Application
Section titled “4. Restart the Application”- After making changes, restart the app from Node.js Selector → Restart App.
- This reloads the configuration and applies your fixes.