Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Fix the Node.js "Cannot GET /" Error

This guide explains why a Node.js app shows "Cannot GET" in the browser and how to fix it.

How-To Guides2 min read11 steps

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

  1. Look at the address in the browser. Compare it with your routes. Addresses are case sensitive on most servers.
  2. Open your main file, often app.js or server.js.
  3. 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.

  1. 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.

  1. Check the order of your code. Routes must come before any "catch all" or error line.
  2. If you use a router file, make sure it is loaded with app.use:
app.use('/api', apiRouter);
  1. 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.
  2. Reload the page. Clear the browser cache if the old error shows.

Check the app settings on hosting

  1. Open your control panel's Node.js app tool, if your plan has one.
  2. Check that the Application root and Startup file point to the right place.
  3. 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.