server.close()
The method that stops a Node.js server accepting new connections and calls back once every existing connection has ended.
In more detail
Kept-alive idle connections can keep it waiting, so recent Node.js versions close idle ones, and closeAllConnections() forces the rest. Pair it with a timeout during shutdown.
Related terms
- graceful shutdown — Stopping a service in an orderly way: finish current work, close connections, then exit.
- connection draining — Stopping new traffic to a backend while letting its existing connections finish, before removing or restarting it.
- node:http — The built-in Node.js module for writing HTTP/1.1 servers and clients, which web frameworks such as Express and Fastify build on.
Taught in
- Close Phase & Signal Dispatch: Sockets & Teardown — Node.js Internals & Backend Services
- Native HTTP Server: Request & Response Lifecycles — Node.js Internals & Backend Services
- Native WebSockets: Bidirectional Real-Time Streams — Node.js Internals & Backend Services
- Production Hardening: Graceful Shutdown & Docker — Node.js Internals & Backend Services