[{"id":"expressbeginner-001","courseId":"express-beginner","domain":"routing","topic":"Route methods with app.get and app.post","prompt":"A signup form submits its data with the POST method to /signup. The developer has only written app.get('/signup', ...), and the form does nothing. Which route method should handle the form?","hint":"Each route method is named after one HTTP method.","explain":"Every request names an HTTP method, and every route is attached to one method. A handler only runs for requests that use the method it was attached to.","source":"https://expressjs.com/en/guide/routing.html","interaction":{"type":"single"},"options":[{"id":"a","text":"app.post('/signup', handler)","why":"app.post attaches the handler to POST requests on that path, so the form's submissions reach it."},{"id":"b","text":"app.get('/signup', handler)","whyNot":"app.get only handles GET requests; the form's submission uses POST, so this existing route never runs for it."},{"id":"c","text":"app.put('/signup', handler)","whyNot":"app.put handles PUT requests, a different HTTP method, so it would not receive a form's POST."},{"id":"d","text":"app.delete('/signup', handler)","whyNot":"app.delete handles DELETE requests only, so it cannot receive a POST submission."}],"answer":"a","explanation":"A route method such as app.get or app.post attaches a handler to one HTTP method and one path; app.post handles POST requests.","concept":"A route method such as app.get or app.post attaches a handler to one HTTP method and one path; app.post handles POST requests.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"app.get('/signup', (req, res) => {\n  res.send('Sign up here');\n});","takeaways":["Match the route method to the HTTP method the client sends, such as app.post for form submissions."]},{"id":"expressbeginner-002","courseId":"express-beginner","domain":"routing","topic":"Exact matching of string paths","prompt":"The app defines app.get('/about', ...) and nothing else. A visitor requests /about/team. What happens?","hint":"Consider how much of the incoming address a route written as plain text is checked against.","explain":"Express tests each route path against the address a client asks for. Plain text or a pattern with placeholders such as :id can be used. How much of the address must the plain text cover?","source":"https://expressjs.com/en/guide/routing.html","interaction":{"type":"single"},"options":[{"id":"a","text":"The /about handler does not run, because string paths match requests exactly","why":"The whole request path must equal /about; /about/team is a different path, so the handler is skipped."},{"id":"b","text":"The /about handler runs, because /about is the start of the requested path","whyNot":"Express does not accept a shorter route path as a match for a longer request path; the two must be equal."},{"id":"c","text":"The /about handler runs and req.params holds 'team'","whyNot":"Only named parameters like :name capture text from the URL; a plain string path captures nothing."},{"id":"d","text":"Express redirects the visitor to /about","whyNot":"Nothing in this app sends a redirect; the route only sends the word about when it runs."}],"answer":"a","explanation":"String paths match requests exactly: the whole request path must equal the route path.","concept":"String paths match requests exactly: the whole request path must equal the route path.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"app.get('/about', (req, res) => {\n  res.send('about');\n});","takeaways":["A route for /about does not answer /about/team; add a route for each path you serve."]},{"id":"expressbeginner-003","courseId":"express-beginner","domain":"routing","topic":"Dots and hyphens in string paths","prompt":"The route app.get('/random.text', ...) also answers a request to /randomXtext, because the dot in a string path matches any single character.","hint":"Think about how a string path differs from a regular expression.","explain":"Route paths can be plain strings or regular expressions, and symbols in them can carry special meanings in one kind but not the other. Work out which kind this route path is.","source":"https://expressjs.com/en/guide/routing.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The dot is literal in a string path, so /randomXtext does not match; only the exact text /random.text does."},{"id":"b","text":"False","why":"The dot and hyphen are interpreted literally in string paths, so /randomXtext cannot match /random.text."}],"answer":"b","explanation":"In string paths the dot and the hyphen are interpreted literally, so they match only themselves.","concept":"In string paths the dot and the hyphen are interpreted literally, so they match only themselves.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"app.get('/random.text', (req, res) => {\n  res.send('random.text');\n});","takeaways":["In a string path, a dot stands for a dot, so /file.txt does not match /filextxt."]},{"id":"expressbeginner-004","courseId":"express-beginner","domain":"routing","topic":"Query strings excluded from route matching","prompt":"The route is app.get('/search', handler). Which TWO of these requests reach this handler?","hint":"Only one part of the URL is compared with the route path.","explain":"A route compares only part of a request's address with its path. Think about which part of the address is the path and which part is added after it.","source":"https://expressjs.com/en/guide/routing.html","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"GET /search?q=shoes","why":"The query string is not part of the route path, so the path /search still matches."},{"id":"b","text":"GET /search?page=2&sort=new","why":"Anything after the ? is ignored for matching, however many parameters it holds."},{"id":"c","text":"GET /search/results","whyNot":"String paths match exactly, so the extra segment makes this a different path and the handler is skipped."},{"id":"d","text":"GET /?q=search","whyNot":"The path is /, not /search; the word in the query string does not affect which route matches."},{"id":"e","text":"GET /search.html","whyNot":"The dot is literal, so /search.html is a different path from /search."},{"id":"f","text":"GET /shop?search=1","whyNot":"The path is /shop; a query parameter named search cannot make the /search route match."}],"answer":"ab","explanation":"Express matches route paths against the path part of the URL only; the query string after ? is not part of matching.","concept":"Express matches route paths against the path part of the URL only; the query string after ? is not part of matching.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"app.get('/search', (req, res) => {\n  res.send(req.query.q);\n});","takeaways":["Query strings are not part of the route path, so they never decide which route runs."]},{"id":"expressbeginner-005","courseId":"express-beginner","domain":"routing","topic":"Named route parameters","prompt":"A route is defined as app.get('/users/:userId/books/:bookId', handler). A request arrives for /users/34/books/8989. What does req.params contain?","hint":"Each named piece of the route path is filled from the matching piece of the URL.","explain":"A route path can contain named placeholders. Each placeholder captures one part of the URL at its position, and the captured text is handed to the handler under the placeholder's name.","source":"https://expressjs.com/en/guide/routing.html","interaction":{"type":"single"},"options":[{"id":"a","text":"{ userId: \"34\", bookId: \"8989\" }","why":"Each name becomes a key, and the segment at its position is stored as a string under it."},{"id":"b","text":"{ userId: 34, bookId: 8989 }","whyNot":"Captured values come back as strings, even when they look like numbers."},{"id":"c","text":"{ users: \"34\", books: \"8989\" }","whyNot":"The fixed words in the path are not parameters; only the names written with a colon become keys."},{"id":"d","text":"{ userId: \"/users/34\", bookId: \"/books/8989\" }","whyNot":"A named parameter captures only its own segment, so the /users/ before it is not included."}],"answer":"a","explanation":"A named route parameter captures one path segment and stores it as a string under its name in req.params.","concept":"A named route parameter captures one path segment and stores it as a string under its name in req.params.","rev":1,"updatedAt":"2026-10-24","kind":"scenario","code":"app.get('/users/:userId/books/:bookId',\n  (req, res) => {\n    res.send(req.params);\n  });","takeaways":["Each named parameter captures one segment, and the values in req.params arrive as strings."]}]