Express.js router.METHOD() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Router

Definition

router.METHOD() is the Express pattern for HTTP verb routes on a router. Replace METHOD with a lowercase verb: router.get(), router.post(), router.put(), router.delete(), and many others. Create the router with express.Router(), then mount it with app.use().

Each call matches one verb on a path relative to the mount. Shared logic for every verb belongs on router.all(). Chain several verbs on one path with router.route(). The app-level twin is app.METHOD().

Syntax

Call router.METHOD in your Express.js app. Start with this line.

Express
router.METHOD(path, callback)
router.METHOD(path, ...callbacks)
router['m-search'](path, callback)
CallWhat it does
router.METHOD(path, callback)Primary signature.
router.METHOD(path, ...callbacks)Related call form.
router['m-search'](path, callback)Related call form.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

router.METHOD(path, callback)
router.METHOD(path, ...callbacks)
router['m-search'](path, callback)

Parameters

ParameterDescription
pathRequired. Path relative to the mount. Strings match the whole remaining path. Arrays match any listed path. See route path syntax.
callbackRequired. One or more handlers: (req, res, next) => { … }. Can call next('route') or next('router') to skip remaining work.
router.getRequired. Read a resource / page
router.postRequired. Create a resource
router.putRequired. Replace / update
router.deleteRequired. Remove a resource
router.patchRequired. Partial update

Return Value

router.METHOD() (lowercase method names such as get, post, …) returns the same router, which is usually ignored.

Express
router.get('/:id', show);
// => router

router.post('/', create).get('/', list);

Express.js Examples

Example 1 — Same Path, Two Verbs

GET and POST on the router root become /books after the mount.

Express
const express = require('express');
const app = express();
const books = express.Router();

books.get('/', (req, res) => {
  res.send('GET request to books');
});

books.post('/', (req, res) => {
  res.send('POST request to books');
});

app.use('/books', books);
app.listen(3000);

How It Works

  1. Mount the module. app.use('/books', books) strips /books before the router sees the request. Inside the router the path is /.
  2. Same path, different verbs. Both handlers use '/' on the router.
  3. GET vs POST. Only the matching verb runs. PUT needs its own router.put (or router.all).
  4. Prefix matters. A request to / never enters this router.

Example 2 — Path Params on a Mounted Router

Capture an id with :id. The public URL is /users/:id.

Express
const express = require('express');
const app = express();
const users = express.Router();

users.get('/:id', (req, res) => {
  res.json({
    id: req.params.id,
    baseUrl: req.baseUrl
  });
});

app.use('/users', users);
app.listen(3000);

How It Works

  1. Register the relative path. users.get('/:id') does not include /users.
  2. Read the param. Express puts the segment in req.params.id.
  3. See the mount. req.baseUrl is /users for this request.
  4. Only GET matches. POST to the same URL needs users.post('/:id', …).

Example 3 — Chain with router.route()

One path, several METHOD handlers without repeating the path string.

Express
const express = require('express');
const app = express();
const catalog = express.Router();

catalog.route('/book')
  .get((req, res) => {
    res.send('Get a book');
  })
  .post((req, res) => {
    res.send('Add a book');
  })
  .put((req, res) => {
    res.send('Update the book');
  });

app.use('/catalog', catalog);
app.listen(3000);

How It Works

  1. One path. catalog.route('/book') names the resource once on the router.
  2. Chain verbs. .get, .post, and .put are METHOD helpers on that route.
  3. Mount adds the prefix. Public URLs are under /catalog.
  4. Fewer typos. You do not repeat '/book' on every line. See router.route().

Runtime Support

router.METHOD() helpers are Express.js router methods. They run on a Node.js server (Express 5 needs Node.js 18+). Browsers only send HTTP requests.

✓ Server · Express 4 & 5

router.METHOD()

Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
router.METHOD() Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It is the family of routing methods on an express.Router() where METHOD is an HTTP verb in lowercase — for example router.get(), router.post(), and router.delete(). Each one matches only that verb.
The matching rules are the same. router.METHOD() lives on a router, so the path is relative to where you mount that router with app.use(). Use it to keep feature routes in their own module.
router.METHOD() matches one HTTP verb. router.all() runs for every verb on that path.
Yes, if you did not register router.head() for that path first. Express also runs the GET handler for HEAD and leaves the body empty.
No. These methods register routes on your Node.js server. Browsers only send HTTP requests with a method and path.

Next: router.param()

Run shared logic whenever a named route parameter appears.

router.param() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful