[{"id":"expressadvanced-001","courseId":"express-advanced","domain":"routing","topic":"mergeParams for parent router params","prompt":"A parent router is mounted at /users/:userId. The child router below is created with mergeParams: true and defines /books/:bookId. A request to /users/34/books/8989 reaches the child. What does req.params hold there?","hint":"Check what the child router's option says about the parent's captured values.","explain":"By default a router's req.params holds only what its own path captures. A setting on the child router decides whether the values captured by the path it is mounted under are carried into that object.","source":"https://expressjs.com/en/5x/api/router/","interaction":{"type":"single"},"options":[{"id":"a","text":"{ userId: '34', bookId: '8989' }","why":"mergeParams keeps the parent's captured values, so both names appear beside the child's own."},{"id":"b","text":"{ bookId: '8989' }","whyNot":"That is the result without mergeParams; here the flag is set, so the parent's userId is kept."},{"id":"c","text":"{ 0: '34', 1: '8989' }","whyNot":"Numeric keys come from unnamed regular-expression routes, not from named parameters like these."},{"id":"d","text":"undefined, because a child router's req.params is reset on mount","whyNot":"req.params is filled with named values; a child router does not reset it to undefined."}],"answer":"a","explanation":"Preserve the req.params values from the parent router. With mergeParams the parent's values are kept, and on a name conflict the child's value takes precedence.","concept":"Preserve the req.params values from the parent router. With mergeParams the parent's values are kept, and on a name conflict the child's value takes precedence.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"const r = Router({ mergeParams: true });\nr.get('/books/:bookId', (req, res) => {\n  res.send(req.params);\n});\napp.use('/users/:userId', r);","takeaways":["mergeParams: true keeps the parent's req.params values in a child router."]},{"id":"expressadvanced-002","courseId":"express-advanced","domain":"routing","topic":"Param callbacks run before handlers","prompt":"An app registers one param callback for :id and :page that logs the value and calls next(). Two GET routes on /user/:id/:page follow: the first logs a line and calls next(); the second logs a line and ends the response. A GET to /user/42/3 prints four lines. Put these four lines in the order they print.","hint":"Think about whether a stage tied to a URL name runs before or after the routes that use that name.","explain":"A named part of a URL can have a stage of its own, shared by every route that uses that name, and it receives the value captured there. Each stage passes control on by calling next.","source":"https://expressjs.com/en/5x/api/application/","interaction":{"type":"sort","items":[{"text":"CALLED ONLY ONCE with 42","why":"The callback for the first declared parameter runs first, before any route handler."},{"text":"CALLED ONLY ONCE with 3","why":"The first callback's next() call reaches the callback for the next declared parameter."},{"text":"although this matches","why":"All param callbacks run before any handler of a route where the parameter occurs, so this handler comes after both."},{"text":"and this matches too","why":"It is the second route's handler, reached because the first handler calls next(); it logs last."}]},"options":[],"answer":"o:abcd","explanation":"Param callbacks run once per request-response cycle, before any handler of a route where the parameter occurs. With several parameters declared together, each callback's next() call reaches the callback for the next one.","concept":"Param callbacks run once per request-response cycle, before any handler of a route where the parameter occurs. With several parameters declared together, each callback's next() call reaches the callback for the next one.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Param callbacks run once per request, before the handlers of routes that use the parameter."]},{"id":"expressadvanced-003","courseId":"express-advanced","domain":"routing","topic":"Param callback scope per router","prompt":"An app registers app.param('id', loader). A router created with Router() is mounted at /items, and its route uses :id. A request to /items/5 arrives. Does loader run for it?","hint":"Consider which object the callback was attached to, and what that object covers.","explain":"A loader attached to a named part of the URL belongs to the object it was attached to. Work out whether a route in a separately created router falls under that object.","source":"https://expressjs.com/en/5x/api/router/","interaction":{"type":"single"},"options":[{"id":"a","text":"No. The callback runs only for parameters on routes defined directly on the app.","why":"A param callback is local to the router where it was defined, and it fires only for parameters on that router's own routes."},{"id":"b","text":"Yes. An app-level param callback applies to every route, including those in mounted routers.","whyNot":"Param callbacks are not inherited by mounted apps or routers, so this route does not trigger the app's callback."},{"id":"c","text":"Yes, but only when the router is created with mergeParams set to true.","whyNot":"mergeParams carries parent req.params values into a child; it does not make the parent's param callback run for child routes."},{"id":"d","text":"Yes. Express copies app-level param callbacks into each router when it is mounted.","whyNot":"Param callbacks are not copied into mounted routers; the app's callback is not inherited."}],"answer":"a","explanation":"Param callback functions are local to the router on which they are defined, are not inherited by mounted apps or routers, and fire only for parameters on that router's own routes.","concept":"Param callback functions are local to the router on which they are defined, are not inherited by mounted apps or routers, and fire only for parameters on that router's own routes.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"app.param('id', loader);\nconst r = Router();\nr.get('/:id', (req, res) => {\n  res.send(req.params.id);\n});\napp.use('/items', r);","takeaways":["app.param callbacks fire only for parameters on routes defined on the same app or router."]},{"id":"expressadvanced-004","courseId":"express-advanced","domain":"routing","topic":"next('router') leaves a router","prompt":"An app mounts a router at /admin, followed by a handler that sends 401. Inside the router, one middleware calls next('router') when there is no x-auth header. Which TWO statements are correct?","hint":"Think about how far a special next argument carries control, compared with skipping one route.","explain":"Calling next with no argument moves to the next matching step. A string argument changes where control goes, and different strings reach different levels of nesting.","source":"https://expressjs.com/en/guide/using-middleware.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"It skips the router's remaining middleware and passes control back out of the router.","why":"next('router') leaves the router instance, bypassing the rest of its middleware."},{"id":"b","text":"The request then moves on to the handler mounted after the router, such as one that sends 401.","why":"After the router, the app runs the next handler in the mount list, which in the example sends 401."},{"id":"c","text":"It skips only the current route, and the router keeps matching its other routes.","whyNot":"That describes next('route'); next('router') leaves the whole router."},{"id":"d","text":"It sends a 401 status to the client directly, with no further handler needed.","whyNot":"The 401 comes from the handler mounted after the router, not from the call itself."},{"id":"e","text":"It ends the whole app, so no handler mounted after the router can run.","whyNot":"The app keeps going, and the handler mounted after the router still runs."},{"id":"f","text":"It must receive an error object, so the request goes to the error-handling middleware.","whyNot":"A string argument is a control signal, not an error; error middleware is reached through next(err)."}],"answer":"ab","explanation":"next('router') exits the current router and passes control out to what follows its mount point; next('route') only skips the remaining callbacks of the current route.","concept":"next('router') exits the current router and passes control out to what follows its mount point; next('route') only skips the remaining callbacks of the current route.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["next('router') leaves the whole router; next('route') leaves only the current route."]},{"id":"expressadvanced-005","courseId":"express-advanced","domain":"routing","topic":"app.del removed in Express 5","prompt":"You upgrade an Express 4 app to Express 5. It still contains app.del('/user/:id', handler). What happens when that line runs?","hint":"Consider whether a removed method is silently ignored or reported when the code runs.","explain":"A method name on the app object either maps to an HTTP verb or it does not. Major releases sometimes remove older compatibility names, so a name that worked earlier may behave differently now.","source":"https://expressjs.com/en/guide/migrating-5.html","interaction":{"type":"single"},"options":[{"id":"a","text":"Express throws an error when that line runs, since app.del is no longer supported.","why":"Express 5 dropped app.del(); calling it throws an error, and app.delete() is the replacement."},{"id":"b","text":"app.del still works as an alias of app.delete, and only logs a deprecation warning.","whyNot":"Express 5 no longer supports the function, so the alias and warning are from older versions."},{"id":"c","text":"The line is silently skipped, so DELETE requests to that path get a 404.","whyNot":"The page says calling the removed function throws an error, so nothing is skipped quietly."},{"id":"d","text":"app.del is treated as app.get, so DELETE requests reach the GET handler.","whyNot":"No mapping to app.get exists; the removed name is not reinterpreted."}],"answer":"a","explanation":"Express 5 no longer supports app.del(); if you use it, an error is thrown, and app.delete() is the way to register HTTP DELETE routes.","concept":"Express 5 no longer supports app.del(); if you use it, an error is thrown, and app.delete() is the way to register HTTP DELETE routes.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"app.del('/user/:id', handler);","takeaways":["app.del() is removed in Express 5; use app.delete() for DELETE routes."]}]