How do you scale an Express server?
Run multiple instances behind a load balancer (horizontal). Use cluster or PM2 to spawn one worker per CPU core. Add Redis for shared session state if you have any. Use Nginx in front for termination and HTTP/2.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Express.js Server Interview Questions and Answers
A function (req, res, next) that runs on every request. It can modify req, send a response, or call next. Examples: json parsing, auth, logging, error handling.
Register an error-handling middleware at the end with four parameters: (err, req, res, next) => {}. In handlers, throw or call next(err). Use a custom ApiError class. Use an async wrapper to catch promise rejections.
app is the Express application. router is a mini-app you mount with app.use('/path', router). Routers group routes by feature (auth, user, feed). You can mount many routers on one app.
Still have questions?
Browse all our FAQs or reach out to our support team
