Registry / http-networking / server-destroy

server-destroy

JSON →
library1.0.1jsnpmunverified

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-destroy
INSTALL
IMPORT
SIG · SERVER-DESTROY
S
server-destroy
http-networkingjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

enableDestroy
const enableDestroy = require('server-destroy');
import enableDestroy from 'server-destroy';
This package is CommonJS-only and does not provide an ESM export. Use `require` for compatibility.
Server
/// <reference types="node" /> import * as net from 'net'; // ... enableDestroy(server as net.Server);
While the package itself is JavaScript, TypeScript type definitions are available via `@types/server-destroy` which extends the `net.Server` interface.

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.

const http = require('http'); const enableDestroy = require('server-destroy'); const PORT = process.env.PORT || 3000; const server = http.createServer((req, res) => { console.log(`Request received for ${req.url}`); res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello from server-destroy demo!'); }); // Enhance the server with a 'destroy' function enableDestroy(server); server.listen(PORT, () => { console.log(`Server listening on port ${PORT}`); }); // Simulate a shutdown after a few seconds setTimeout(() => { console.log('Initiating server shutdown...'); server.destroy((err) => { if (err) { console.error('Error during server destruction:', err); } else { console.log('Server and all connections destroyed successfully.'); process.exit(0); } }); }, 5000); // Handle process exit signals to ensure clean shutdown process.on('SIGTERM', () => server.destroy(() => process.exit(0))); process.on('SIGINT', () => server.destroy(() => process.exit(0)));
Debug
Known issues
gotchaThis package is CommonJS-only (`require()`). Attempting to use `import` syntax in an ES Module project will result in runtime errors. Ensure your project is configured for CommonJS or use a CJS wrapper if absolutely necessary.
fix
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.
affects: 1.0.1
deprecatedThe `server-destroy` package has not been updated since October 2015 and is no longer actively maintained. While it may still function for its intended purpose, it will not receive bug fixes, security updates, or compatibility improvements for newer Node.js versions or evolving ecosystem standards.
fix
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.
affects: 1.0.1
gotchaNode.js versions 18.2.0 and higher now include a native `server.closeAllConnections()` method, which offers similar functionality to `server-destroy` for closing all active connections. For modern applications, using the built-in method is generally preferred to reduce external dependencies and ensure compatibility with the Node.js core.
fix
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.
affects: <18.2.0
Errors
Common errors & fixes
ReferenceError: require is not defined in ES module scope
You are attempting to use the CommonJS `require()` function in an ECMAScript Module (ESM) file or project.
fix
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()`.
Error: listen EADDRINUSE: address already in use :::<port_number>
A previous server instance or another process is still holding the port open, often because active connections were not properly closed during shutdown.
fix
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.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
3 hits · last 30 days
node
2
OpenAI (training)
1
Resources
server-destroy — npm install server-destroy · libregistry