Express Router Methods

About This Index
This page is the Express Router index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Create a modular stack with express.Router(), then use router.use(), router.METHOD(), and router.route(). Mount the router on the app with app.use(). The factory itself is covered under express.Router().
Start with router.use() and a GET via router.METHOD()—then router.route() and router.param() as your modules grow.
How to Call a Router Method
Build a Router, add middleware and routes, then mount it on the app:
const express = require("express");
const app = express();
const users = express.Router();
users.use((req, res, next) => {
console.log("users router:", req.method, req.path);
next();
});
users.param("id", (req, res, next, id) => {
req.userId = id;
next();
});
users.route("/")
.get((req, res) => res.json([]))
.post((req, res) => res.sendStatus(201));
users.get("/:id", (req, res) => {
res.json({ id: req.userId });
});
app.use("/users", users);
app.listen(3000); Express Router Methods Table
All Router method guides in this Express.js tutorial series (5 tutorials).
Middleware
1 methodBuild the Router pipeline — mount middleware and nested routers.
| Method | Description | Tutorial |
|---|---|---|
router.use() | Mount middleware or nested routers on this Router — the modular pipeline. | Try it |
HTTP Routing
3 methodsDefine routes by method and path — all, METHOD, and route().
| Method | Description | Tutorial |
|---|---|---|
router.all() | Match a path for every HTTP method — shared logic before method-specific routes. | Try it |
router.METHOD() | Register a route for any HTTP verb — get, post, put, patch, delete, and more. | Try it |
router.route() | Create a chainable route for one path — attach .get(), .post(), and more together. | Try it |
Params
1 methodRun logic when named route parameters appear in the URL.
| Method | Description | Tutorial |
|---|---|---|
router.param() | Run callback middleware when a named route parameter is present. | Try it |
Frequently Asked Questions
Start with router.use()
Open the middleware guide—syntax, examples, and FAQs.
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.
16 people found this page helpful
