Stoppable is a Node.js library that decorates standard `http.Server` and `https.Server` instances with a `stop()` method, addressing a long-standing behavior of Node.js's native `server.close()` that often leaves existing connections open indefinitely. This library ensures a graceful shutdown by stopping new connections, allowing in-flight requests to complete, and then closing existing idle connections, optionally with a grace period for force-closing. The current stable version is 1.1.0, last updated in 2017. While widely adopted and stable for its intended purpose, it is no longer actively maintained. Its key differentiator is providing a reliable, explicit mechanism for graceful server shutdown that was historically missing from Node.js core, with minimal performance overhead. Alternatives like `http-terminator` offer similar functionality with different design choices, often avoiding monkey-patching.
npm install stoppableVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create an HTTP server, make it stoppable with a grace period, and handle `SIGTERM`/`SIGINT` signals for graceful shutdown, allowing in-flight requests to complete.
Always explicitly pass a finite `grace` period (e.g., `stoppable(server, 5000)`) or `0` for immediate termination, depending on your application's requirements.
Be aware of potential conflicts when combining `stoppable` with other server-modifying libraries. Thorough testing is recommended, especially after Node.js version upgrades.
For applications on modern Node.js versions, consider native Node.js solutions or more actively maintained alternatives like `http-terminator` that may provide more robust or contemporary approaches to graceful shutdown without monkey-patching. Evaluate `stoppable`'s continued relevance and compatibility with your target Node.js runtime.
Ensure you correctly decorate the server: `const server = stoppable(http.createServer(handler));` or `stoppable(serverInstance);` if `serverInstance` is already defined.
When calling `stoppable(server, grace)`, ensure `grace` is set to a finite number of milliseconds (e.g., 5000 for 5 seconds) to force-close connections after the grace period. Set `grace` to `0` to kill all sockets immediately without waiting.
No dependency data recorded yet.