A. res.send() cannot be used twice in the same app.
B. Missing next() call causes the second route to fail.
C. Routes must use app.post() instead of app.get().
D. Duplicate route paths cause only the first handler to run.
Solution
Step 1: Check route definitions
Both routes use the same path '/user' with app.get(), which causes the first matching route to handle requests.
Step 2: Understand Express routing behavior
Express matches routes in order and stops at the first match unless next() is called, so the second route is ignored.
Final Answer:
Duplicate route paths cause only the first handler to run. -> Option D
Quick Check:
Duplicate routes = first match wins [OK]
Hint: Same path routes: only first runs unless next() used [OK]
Common Mistakes:
Thinking both routes run automatically
Believing next() is required in route handlers
Confusing HTTP methods with route conflicts
5. You want to create an Express app that uses a router for '/api' routes and a middleware to log request times only for those routes. Which pattern correctly applies this?
hard
A. Create router, add logging middleware globally with app.use(), then use router;
B. Create a router, add logging middleware to it, then use app.use('/api', router);
C. Add logging middleware globally with app.use(), then create router for '/api';
D. Use app.get('/api', loggingMiddleware, router);
Solution
Step 1: Understand middleware scope
To log only '/api' routes, middleware must be attached to the router handling those routes.
Step 2: Apply middleware to router and mount router
Create router, add logging middleware to it, then mount router on '/api' with app.use('/api', router).
Final Answer:
Create a router, add logging middleware to it, then use app.use('/api', router); -> Option B
Quick Check:
Router middleware limits logging to '/api' [OK]
Hint: Attach middleware to router, then mount router [OK]
Common Mistakes:
Adding middleware globally when only '/api' needs it
Trying to pass router as middleware in app.get()
Not mounting router properly on '/api'
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.