What does the error mean?
Node.js lets you run JavaScript on a server. Many Node apps use a helper called Express. A visitor opens a page by sending a GET request, which is just "please show me this page". The message Cannot GET /something means your app has no rule for that address. The app is running, but it does not know what to show.
Common causes
- There is no route for that address in your code.
- The address has a typing mistake or the wrong capital letters.
- Your files were not found, so the home page is missing.
- The app is set to the wrong base path or startup file.
- The route is defined after a line that already ended the request.
Steps to fix it
- Look at the address in the browser. Compare it with your routes. Addresses are case sensitive on most servers.
- Open your main file, often
app.jsorserver.js. - Check that a route exists for the address. For the home page it looks like this:
app.get('/', (req, res) => {
res.send('Hello from my app');
});
This tells the app what to send when someone opens the home page.
- If you want to show HTML files from a folder, serve them as static files:
app.use(express.static('public'));
Now a file at public/index.html opens at the home page.
- Check the order of your code. Routes must come before any "catch all" or error line.
- If you use a router file, make sure it is loaded with
app.use:
app.use('/api', apiRouter);
- Save the file and restart the app. In a hosting control panel with a Node.js tool, use its Restart button. On a server, restart your process manager.
- Reload the page. Clear the browser cache if the old error shows.
Check the app settings on hosting
- Open your control panel's Node.js app tool, if your plan has one.
- Check that the Application root and Startup file point to the right place.
- Check the application URL matches the address you visit.
Tip: Look in the app's log file for hints. If you cannot find the cause, send the log to Hostvento support through a support ticket.
Quick recap
- "Cannot GET" means no route matches the address.
- Add a route or serve static files.
- Check spelling, letter case and code order.
- Restart the app after every change.