Skip to content

Node.js and Express errorExpress: “Cannot GET /path”

The browser shows a plain page that says Cannot GET / (or Cannot GET /about, Cannot GET /api/users), with status 404. That text is Express’s default answer when no route or static file matched the request. The server is running; it just has nothing registered for that method and path.

Short answer

Check that a route exists for that exact method and path: app.get('/') for the home page, and a GET route if you typed the URL into the browser, because browsers only send GET. If you serve a front end, point express.static at the right folder with path.join(__dirname, 'public') and make sure index.html is inside it. For a React, Vue or Vite app, add a fallback after your API routes that sends index.html for other GET requests, so refreshing a client route works.

Why no route matched, and the fix

  1. 01

    No route for that method and path

    “Express has executed all middleware functions and routes, and found that none of them responded.” Express, FAQ: How do I handle 404 responses?

    Express matches the method and the path together. A route defined with app.post('/login') does not answer a GET to /login, and a router mounted at /api does not answer /users. Check the spelling, the mount prefix and the method, and add a route for the page you open in the browser.

    app.get('/', (req, res) => res.send('OK'));
    
    const api = express.Router();
    api.get('/users', listUsers);
    app.use('/api', api);   // serves GET /api/users
  2. 02

    The static folder path is wrong

    “Express looks up the files relative to the static directory, so the name of the static directory is not part of the URL.” Express, Serving static files in Express

    express.static('public') is resolved from the folder you started node in, not from the file. Start the server from somewhere else, or deploy with a different working directory, and nothing is found. Build the path from the file’s folder (in an ES module, use import.meta.dirname). The folder name itself is not part of the URL.

    const path = require('node:path');
    app.use(express.static(path.join(__dirname, 'public')));
    // public/index.html is served at /, public/css/app.css at /css/app.css
  3. 03

    A single-page app route on refresh

    React Router, Vue Router and similar libraries handle /dashboard in the browser, but a refresh asks the server for /dashboard, and Express has no such route. After the API routes and static middleware, send index.html for any other GET request. This form works on Express 4 and 5.

    const dist = path.join(__dirname, 'dist');
    app.use(express.static(dist));
    app.use((req, res, next) => {
      if (req.method !== 'GET' || req.path.startsWith('/api/')) return next();
      res.sendFile(path.join(dist, 'index.html'));
    });
  4. 04

    Show your own 404 page

    “In Express, 404 responses are not the result of an error, so the error-handler middleware will not capture them.” Express, FAQ: How do I handle 404 responses?

    The plain Cannot GET text is the built-in fallback. A 404 is not an error in Express, so an error handler does not catch it. Add a last middleware that answers with your own page or JSON.

    app.use((req, res) => {
      res.status(404).json({ error: `No route for ${req.method} ${req.path}` });
    });

Checked against the vendor’s docs on : Express: FAQ (How do I handle 404 responses?); Express: Serving static files.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: Page not found on refresh (Netlify, Vercel) · “Unexpected token < in JSON” · Node.js EADDRINUSE: address already in use

Questions

More on this error

Why does Postman work but the browser says Cannot GET?

Postman can send POST, PUT or DELETE; typing a URL into the browser always sends GET. If the route is app.post(), the browser gets Cannot GET. Add a GET route for pages, or call the POST route from a form or fetch.

It works locally but not after deploying. Why?

The host starts the app from a different folder, so a relative static path points nowhere, or the front-end build was not run on the server. Use path.join(__dirname, ...) and check the build output exists in the deploy.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.