Registry / testing / server-with-kill

server-with-kill

JSON →
library1.0.0jsnpmunverified

This package provides a utility to augment Node.js `http.Server` instances with a `kill` method that forcibly destroys all active connections. This functionality is particularly useful in development environments or during testing where immediate server shutdown is required without waiting for connections to naturally close. The current stable version is 1.0.0, released in October 2019. Given the age of the last release and lack of further updates, it can be considered abandoned. It differentiates itself by offering a simple, direct way to manage server connections beyond the standard `server.close()` which waits for active connections to finish. Its primary use case is to ensure a clean slate for server processes, especially in automated test suites.

npm install server-with-kill
INSTALL
IMPORT
SIG · SERVER-WITH-KILL
S
server-with-kill
testingjavascriptv1.0.0
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.

transform
import { transform } from 'server-with-kill';
import serverWithKill from 'server-with-kill';
The primary utility is a named export `transform`.
transform
const { transform } = require('server-with-kill');
const transform = require('server-with-kill');
CommonJS require style for named export.
ServerWithKill
import { ServerWithKill } from 'server-with-kill/dist/types/server-with-kill.d.ts'; // For type-only imports, though typically inferred
The package ships TypeScript types; `transform` returns a `ServerWithKill` interface extending `http.Server`.

Demonstrates starting an Express server, wrapping it with `server-with-kill`'s `transform` function, and then forcibly shutting it down after a set delay, including a simulated long task.

import express from 'express'; import { transform } from 'server-with-kill'; import { Server } from 'http'; const app = express(); const PORT = 3000; app.get('/', (req, res) => { res.send('Hello from server-with-kill! This server will be killed soon.'); }); app.get('/long-task', (req, res) => { console.log('Received request for long-task...'); // Simulate a long-running process that might be interrupted by kill setTimeout(() => { res.send('Long task completed (if not killed)!'); }, 5000); }); const httpServer: Server = app.listen(PORT, () => { console.log(`Server listening on http://localhost:${PORT}`); }); const serverWithKill = transform(httpServer); console.log('Server started. It will be forcibly killed in 3 seconds.'); setTimeout(() => { serverWithKill.kill((err) => { if (err) { console.error('Error during server kill:', err.message); } else { console.log('Server killed and all active connections destroyed.'); } process.exit(0); }); }, 3000);
Debug
Known issues
breakingThe package has not been updated since its initial release in October 2019 (v1.0.0). It may not be fully compatible with newer Node.js versions or could have unresolved security vulnerabilities related to Node's internal `http` module changes. Relying on an unmaintained package for production is risky.
fix
Consider alternatives like `kill-port` for process killing, or manually managing `server.close()` with connection tracking for more controlled shutdowns if full compatibility and ongoing support are required.
affects: >=1.0.0
gotchaForcibly destroying connections with `server.kill()` can lead to unexpected client behavior, data loss, or corrupted states if clients are in the middle of a request/response cycle. It's an immediate, blunt instrument.
fix
Use `server.kill()` primarily in testing or development environments where data integrity of active connections is not a primary concern. In production, prefer graceful shutdowns with `server.close()` and connection draining.
affects: >=1.0.0
gotchaThe `kill` method accepts an optional callback, but it's important to handle errors that might occur during the destruction of sockets. While less common, socket destruction can sometimes fail.
fix
Always provide a callback to `serverWithKill.kill()` and check for an `err` argument to properly log or handle any issues that arise during the forced termination process.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: server.kill is not a function
Attempting to call `.kill()` directly on a standard `http.Server` instance without first transforming it with `server-with-kill`.
fix
Ensure you pass your `http.Server` instance through the `transform` function: `const serverWithKill = transform(yourHttpServer);`
Error: read ECONNRESET
A client received a 'connection reset' error because the server forcibly closed the connection using `server.kill()` while the client was still active.
fix
This is an expected outcome when using `server.kill()`. It signifies that the connections were indeed destroyed. It's a 'problem' for the client, not necessarily the server. Inform clients that the server might abruptly shut down, or design your architecture to handle sudden disconnections.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
1
Resources
server-with-kill — npm install server-with-kill · libregistry