Interview Q&A / Node.js
Node.js interview questions
The event loop on the server, streams, modules and building APIs with Express.
Prefer rapid revision? Practise Node.js short interview answers →
- How do you return a custom 404 response for unknown routes in Express?
Add a middleware with no path after all your routes. If no earlier route replied, the request reaches it, and you send a 404 status with a JSON or HTML body.
BeginnerQuick answer1 min read - What is express.Router and why use it?
express.Router creates a mini app that holds a group of related routes and middleware. You mount it under a path prefix, which keeps large apps organised by feature.
BeginnerQuick answer1 min read - What is the difference between route parameters and query strings in Express?
Route parameters are part of the path, like /users/42, and identify a specific resource, read from req.params. Query strings follow a question mark, like ?page=2, and filter or tweak a request, read from req.query.
BeginnerQuick answer1 min read - Why does the order of middleware and routes matter in Express?
Express runs middleware and routes in the order they are registered, and a response ends the chain. A parser placed after a route never runs for it, and a catch-all placed early swallows later routes.
BeginnerQuick answer1 min read