Destroyable-Server, currently at version 1.1.1, is a compact Node.js module designed to enhance the `net.Server` API by providing a reliable and immediate mechanism to terminate all active client connections. When `server.close()` is invoked, it merely ceases to accept new connections, often leaving existing ones open and preventing the Node.js process from exiting cleanly. This library introduces a `destroy()` method to server instances via its `makeDestroyable` utility, which not only stops listening but also forcibly closes every tracked socket. This capability is critical for scenarios requiring rapid server restarts, robust test suite teardowns, or graceful application shutdowns. It works across various `net.Server` subclasses, including HTTP and TLS, and uniquely offers a promise-based interface for awaiting complete connection termination, differentiating it from `server.closeIdleConnections()` which might miss active connections or not be universally available. The project maintains a stable, low-cadence release cycle, reflecting its focused utility and role as part of HTTP Toolkit.
npm install destroyable-serverVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating a Node.js TCP server, making it destroyable, and then gracefully shutting it down by forcibly closing all active connections after a delay.
While the mutation is intended behavior, developers should treat the return value of `makeDestroyable` as the primary reference for the enhanced server, as shown in `server = makeDestroyable(server);`.
Always use `await server.destroy();` when initiating a shutdown to ensure complete resource cleanup before continuing or exiting the process.
Ensure that the object passed to `makeDestroyable` is an instance of `net.Server` or a compatible derivative like `http.Server` or `https.Server`.
Ensure you have called `server = makeDestroyable(server);` (or similar assignment) on your server instance before attempting to invoke `server.destroy()`.
Always `await server.destroy()` during shutdown routines to guarantee that all connections are closed and the port is released before attempting to restart the server or exit the process.
No dependency data recorded yet.