Routing
Routing maps incoming client requests to specific server execution paths. By utilizing dynamic parameters, HTTP method verbs, and isolated Express Routers, developers build highly organized API structures.
Knowledge Check
2 questions · pass at 70%
1. How does Express evaluate route matching when multiple routes match the same incoming request path?
Interview Questions
1 questionsCheatsheet
Download-ready referenceRoute Param Dynamic path placeholder (/:id) -> req.params.id
Query Param URL search string (?key=val) -> req.query.key
express.Router Modular path mounting helper.
Basic Setup:
const app = express();
app.get('/items', (req, res) => res.json(items));
Router Module:
// routes/items.js
const router = express.Router();
router.get('/', (req, res) => res.send());
export default router;
Mounting Router:
app.use('/items', itemsRouter); // matches GET /items