server-destroy is a lightweight Node.js utility designed to enhance `http.Server` or `net.Server` instances with a `destroy()` method. This method allows for the graceful shutdown of a server by not only stopping it from accepting new connections but also forcibly closing all existing open connections, a feature not natively present in older Node.js versions. The package is stable at version 1.0.1 but has not seen updates since its last publish in October 2015, making it effectively abandoned. Its release cadence is non-existent. Key differentiators at the time of its release were providing a complete server shutdown mechanism beyond `server.close()`, which only stops listening for new connections. With Node.js v18.2.0 and later, similar functionality is available natively via `server.closeAllConnections()`. Therefore, this package is primarily useful for projects targeting older Node.js runtimes.
npm install server-destroyVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create an HTTP server, enhance it with the `destroy` method using `server-destroy`, and then gracefully shut it down, closing all active connections after 5 seconds. It also shows basic signal handling.
Use `const enableDestroy = require('server-destroy');` in your CommonJS modules. If you are in an ESM project, consider using Node.js's native `server.closeAllConnections()` available in Node.js 18.2.0+ as an alternative.For new projects or when upgrading Node.js versions, consider migrating to Node.js's native `server.closeAllConnections()` method (available in Node.js v18.2.0 and later) which provides similar functionality.
If targeting Node.js >=18.2.0, switch to using `server.closeAllConnections()` for graceful server shutdown. For older Node.js versions, `server-destroy` remains a viable option.
Ensure your file is a CommonJS module (e.g., `.js` file without `"type": "module"` in `package.json`, or explicitly using `.cjs` extension). If you must use ESM, for Node.js v18.2.0+, consider using the native `server.closeAllConnections()`.
Ensure your server's shutdown logic explicitly calls `server.destroy()` (or `server.closeAllConnections()` for newer Node.js versions) to terminate all open connections. For lingering processes, use `kill -9 <PID>` on Linux/macOS or Task Manager on Windows to manually terminate the process.
No dependency data recorded yet.