Express.js
Routing, middleware, error handling, and Express patterns asked in Node backend interviews.
Fundamentals
Routing
Routing Basics
Defining routes with app.get/post/put/delete and sending responses.
Route Parameters & Query Strings
Reading dynamic URL segments with req.params and ?key=value with req.query.
Router & Modular Routes
Use express.Router() to split routes across files and keep large apps organized.
Middleware
Middleware Concept
The core mental model of Express — req, res, next, and the pipeline.
Built-in Middleware
express.json, express.urlencoded, express.static, and express.Router.
Third-party Middleware
The essential npm middleware: cors, helmet, morgan, compression, cookie-parser, and body-parser — what each does and when to reach for it.
Error-handling Middleware
The special 4-argument middleware that catches errors thrown anywhere in our app — why the signature matters and why order is everything.
Request & Response
Request Object
Everything we can pull off req: params, query, body, headers, cookies, ip, path — the data we need from the client.
Response Object
The res object — sending JSON, setting status codes, redirects, file downloads, and chaining it all together.
Static Files & Templating
Serving CSS/JS/images with express.static, and rendering HTML on the server with EJS, Pug, or Handlebars.
Security
CORS
Cross-Origin Resource Sharing — why the browser blocks our frontend from calling our API, and how the cors middleware fixes it.
Helmet
One line of middleware that sets a dozen security headers — what they block and why each one matters.
Rate Limiting
Protecting Express APIs from abuse with express-rate-limit, comparing algorithms and stores.
Auth & Validation
Authentication Patterns
Passport.js strategies vs custom middleware, plus refresh token flows in Express.
Sessions vs JWT
The classic interview tradeoff: stateful sessions with Redis vs stateless JWT tokens.
Request Validation
Validating bodies, queries and params with express-validator, Zod, and Joi.
Production
File Uploads (multer)
Handling multipart/form-data uploads in Express with disk vs memory storage.
Async Error Handling
The Express 4 async/await catch-22, the express-async-errors patch, and Express 5's native fix.
Testing with Supertest
Testing Express routes without running a server, using Jest/Vitest + Supertest.