C. Second route has incorrect syntax; missing callback function.
D. res.send() cannot be used inside app.get().
Solution
Step 1: Check syntax of second route
The second app.get('/hello') lacks a callback function and uses braces incorrectly.
Step 2: Verify other options
First route is correct; duplicate routes are allowed; res.send() is valid inside app.get().
Final Answer:
Second route has incorrect syntax; missing callback function. -> Option C
Quick Check:
Syntax error in second route = Second route has incorrect syntax; missing callback function. [OK]
Hint: Check for callback function syntax in routes [OK]
Common Mistakes:
Thinking duplicate routes are invalid
Believing res.send() is disallowed
Ignoring missing arrow function or callback
5. You want to create an Express app that responds with 'Hello, user!' when visiting /user/:name, where :name is any username. Which code correctly implements this dynamic routing?
hard
A. app.get('/user/name', (req, res) => { res.send('Hello, name!'); });
B. app.get('/user/:name', (req, res) => { res.send(`Hello, ${req.params.name}!`); });
C. app.get('/user/:name', (req, res) => { res.send('Hello, user!'); });
D. app.get('/user/:name', (req, res) => { res.send(req.query.name); });
Solution
Step 1: Understand dynamic route parameter usage
Express uses :name to capture dynamic parts in req.params.name.
Step 2: Check each option
app.get('/user/:name', (req, res) => { res.send(`Hello, ${req.params.name}!`); }); uses req.params.name correctly to personalize the message. The static '/user/name' option sends fixed text, the dynamic path with fixed 'Hello, user!' ignores the parameter, and req.query.name is for query strings (?name=foo), not path parameters (/user/foo).