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

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

This message shows in the browser when your Node.js app has no answer for the address you opened. This guide shows how to fix it.

Web Hosting2 min read8 steps

What does it mean?

A Node.js app uses routes. A route is a rule that says "when someone visits this address, send this answer". Think of a shop with signs on each door. If you walk to a door with no sign, nobody answers. "Cannot GET /" means the app is running, but it has no route for that address. GET is the kind of request a browser makes when it asks for a page.

Common causes

  • No route is set for the path, such as / or /about.
  • The route is written after another rule that catches everything.
  • A typing mistake in the path.
  • The app uses the wrong method, for example app.post instead of app.get.
  • Static files such as index.html are not served.
  • The wrong folder or app is running.

Steps to fix it

  1. Open your main file, such as app.js or server.js.
  2. Look for the route for the path you opened. For the home page, you need something like this:
app.get('/', (req, res) => {
  res.send('Hello from my app');
});

This sends a message when someone opens the home page.

  1. If you want to show an HTML file, serve a folder of files. This example uses a folder called public:
app.use(express.static('public'));

This tells Express, a common Node.js tool, to share the files inside public. Put your index.html there.

  1. Check that the route uses app.get for pages that a browser opens.
  2. Check the spelling and the letter case of the path. /About and /about can differ.
  3. If you use a router file, make sure it is added to the app:
app.use('/', require('./routes/index'));

This connects the routes in that file to your app.

  1. Stop the app and start it again so it loads your changes:
node app.js

If you use PM2, run pm2 restart all.

  1. Open the address in your browser again.

On a hosting panel

If you use a Node.js app tool in your control panel, check that the application root and startup file point to the right folder and file. Then restart the app from the panel. If you are unsure, open a support ticket.

Tip: Add a catch-all route at the very end that shows a friendly "page not found" message.

Quick recap

  • "Cannot GET" means no route matches the address.
  • Add or fix a route with app.get.
  • Serve static files with express.static.
  • Restart the app after every change.