What is the Express.js application lifecycle?
Answer
Understanding the Express application lifecycle helps diagnose bugs. Startup: app.js executes — middleware is registered, routes are defined, database connections are established. Listening: app.listen() creates an HTTP server and starts the event loop waiting for connections. Request handling: for each request, Express traverses the middleware stack in order — each middleware calls next() or sends a response. If no route matches, the request falls through to a 404 handler. If a middleware calls next(err), error-handling middleware takes over. Response: once res.send() or similar is called, the response is sent. The connection may be kept alive (HTTP/1.1 keep-alive) for subsequent requests. Shutdown: server.close() stops new connections; process exits after in-flight requests complete.
Previous
How do you implement request tracing and correlation IDs in Express?
Next
What is the role of reverse proxies in Express.js production deployments?
More Express.js Questions
View all →- Advanced How do you implement WebSocket support alongside Express.js?
- Advanced What are security best practices for Express.js APIs?
- Advanced How does clustering work in Node.js/Express for better performance?
- Advanced What is the difference between Express 4.x and Express 5.x?
- Advanced How do you implement a graceful shutdown in Express.js?