[{"id":"expressintermediate-001","courseId":"express-intermediate","domain":"routing","topic":"next('route') to skip route callbacks","prompt":"A route handles GET /user/:id. Its callback calls next('route') when the id is '0'. A request for GET /user/0 arrives. What happens next?","hint":"Compare what a plain next() does with what this special argument does.","explain":"Each callback hands control onward by calling next. A plain call moves to the following step in the chain. A special argument changes where control goes, so think about how far it reaches.","source":"https://expressjs.com/en/guide/routing.html","interaction":{"type":"single"},"options":[{"id":"a","text":"Express skips the rest of this route's callbacks and tries the next route that matches.","why":"next('route') bypasses the remaining callbacks of the current route and passes the request to the next matching route."},{"id":"b","text":"Express runs the next callback in this same route, then stops.","whyNot":"That is what a plain next() does; next('route') leaves the route instead of moving within it."},{"id":"c","text":"Express sends a 404 at once, because the route was abandoned.","whyNot":"A 404 comes only when no route ends the request; a later matching route still receives it."},{"id":"d","text":"Express ends the response with an empty body and runs no other routes.","whyNot":"next('route') does not end the response; it passes the request onward to other routes."}],"answer":"a","explanation":"next('route') skips the remaining callbacks of the current route and passes the request to the next matching route, while a plain next() only moves to the following callback.","concept":"next('route') skips the remaining callbacks of the current route and passes the request to the next matching route, while a plain next() only moves to the following callback.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"app.get('/user/:id', (req, res, next) => {\n  if (req.params.id === '0') {\n    return next('route');\n  }\n  res.send(`User ${req.params.id}`);\n});","takeaways":["next('route') leaves the current route; a plain next() stays inside it."]},{"id":"expressintermediate-002","courseId":"express-intermediate","domain":"routing","topic":"Reserved characters in route paths","prompt":"In a route path string, a bare plus sign (+) matches a literal plus sign in the request URL, with no escaping needed.","hint":"Some symbols in route paths already have a job of their own.","explain":"A route path string uses a few symbols as pattern syntax, while other characters are read literally. When a symbol needs to be read literally, the string has to mark it somehow.","source":"https://expressjs.com/en/guide/routing.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"+ is a reserved character in route paths, so a bare + is not read as a literal plus; it must be escaped with a backslash."},{"id":"b","text":"False","why":"Reserved characters such as + cannot be used literally unless escaped with a backslash, as in \\+."}],"answer":"b","explanation":"The characters ?, +, *, [], (), and ! are reserved in route paths and cannot be used as literal characters; escape them with a backslash.","concept":"The characters ?, +, *, [], (), and ! are reserved in route paths and cannot be used as literal characters; escape them with a backslash.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Escape reserved route-path characters such as + with a backslash."]},{"id":"expressintermediate-003","courseId":"express-intermediate","domain":"routing","topic":"express.Router as a mountable module","prompt":"An app mounts two routers at /users. authRouter has basic-auth middleware added with use. openRouter has a GET /:user_id route. A request for GET /users/42 reaches openRouter's route. Does the auth middleware also run for it?","hint":"Consider what decides when a middleware function runs, and which router object defined it.","explain":"A grouping object lets you write handlers in one place; Express then attaches each one at the locations you give. To predict what runs for a request, know what its URL is compared against at each attachment.","source":"https://expressjs.com/en/5x/api/router/","interaction":{"type":"single"},"options":[{"id":"a","text":"Yes, because the path it is mounted on decides which requests it sees, not the router that defined it.","why":"Both routers are mounted on /users, so the auth middleware runs on the routes defined by openRouter as well."},{"id":"b","text":"No, middleware added through a router only runs for that router's own routes.","whyNot":"Both routers share the /users mount, so the middleware reaches openRouter's routes too."},{"id":"c","text":"No, it only runs for the /:user_id/edit route, since that is the only route authRouter defines.","whyNot":"A router's own routes do not limit its middleware; the mount path decides where the middleware applies."},{"id":"d","text":"Only if openRouter's route calls next() before it sends a response.","whyNot":"Calling next() does not trigger the middleware; it runs because the request matches the mount path."}],"answer":"a","explanation":"Middleware added through a router runs for any request whose path matches the mount point, including routes defined by a different router mounted at the same path.","concept":"Middleware added through a router runs for any request whose path matches the mount point, including routes defined by a different router mounted at the same path.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"const authRouter = express.Router();\nconst openRouter = express.Router();\nauthRouter.use(basic(usersdb));\nopenRouter.get('/:user_id', viewUser);\napp.use('/users', authRouter);\napp.use('/users', openRouter);","takeaways":["Router middleware is scoped by mount path, so routers sharing a path share it."]},{"id":"expressintermediate-004","courseId":"express-intermediate","domain":"routing","topic":"Mount path hidden from router middleware","prompt":"Four router.use calls sit in one router, written top to bottom below. A request passes through this router without being answered early. Put the four calls in the order the router invokes them.","hint":"Consider what the router does with each call, one after another.","explain":"Calls in one router run one after another, and each call can pass control onward or keep it. Think about what happens to a request that reaches a call, and how setup order shapes that.","source":"https://expressjs.com/en/5x/api/router/","interaction":{"type":"sort","items":[{"text":"express.static('public')","why":"Declared first, so it is invoked before any other call and gets the first chance to serve files."},{"text":"logger()","why":"Declared second, so it sees the requests that the first call passes along with next()."},{"text":"router.use('/bar', barHandler)","why":"Declared third; it runs only for paths under /bar, after the logger has had its turn."},{"text":"final handler that calls res.send('done')","why":"Declared last, so it is reached only after the earlier calls pass control along with next()."}]},"options":[],"answer":"o:abcd","explanation":"Middleware in one router is invoked sequentially in the order it was defined with router.use(), so that order decides which call gets the request first.","concept":"Middleware in one router is invoked sequentially in the order it was defined with router.use(), so that order decides which call gets the request first.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"router.use(express.static('public'));\nrouter.use(logger());\nrouter.use('/bar', barHandler);\nrouter.use((req, res) => {\n  res.send('done');\n});","takeaways":["Router middleware runs in definition order, so placement sets precedence."]},{"id":"expressintermediate-005","courseId":"express-intermediate","domain":"routing","topic":"Regular expression route paths","prompt":"A route is defined as app.get(/.*fly$/, handler). Which request path reaches this handler?","hint":"Look closely at what the dollar sign asks for.","explain":"A regular expression route path is tested against the request path and can match a pattern anywhere in it. End-of-string anchors pin the pattern to a particular edge of the path.","source":"https://expressjs.com/en/guide/routing.html","interaction":{"type":"single"},"options":[{"id":"a","text":"GET /butterfly","why":"The pattern ends with fly, and .* can absorb everything before it, so the whole path matches."},{"id":"b","text":"GET /flyover","whyNot":"fly appears in the middle of this path, followed by more characters, so the end anchor fails."},{"id":"c","text":"GET /fly-by","whyNot":"The path ends with by, not fly, so the pattern does not match."},{"id":"d","text":"GET /flying","whyNot":"The path ends with ing, so it does not end with fly and the handler is not reached."}],"answer":"a","explanation":"A regular expression route such as /.*fly$/ matches paths ending with fly, such as butterfly, while /a/ matches any path containing a.","concept":"A regular expression route such as /.*fly$/ matches paths ending with fly, such as butterfly, while /a/ matches any path containing a.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","takeaways":["Regex route paths follow the pattern exactly, so read the anchors first."]}]