{"id":14910,"library":"server-with-kill","title":"Server with Kill Method","description":"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.","status":"abandoned","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/kenneth-gray/server-with-kill","tags":["javascript","server","typescript"],"install":[{"cmd":"npm install server-with-kill","lang":"bash","label":"npm"},{"cmd":"yarn add server-with-kill","lang":"bash","label":"yarn"},{"cmd":"pnpm add server-with-kill","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary utility is a named export `transform`.","wrong":"import serverWithKill from 'server-with-kill';","symbol":"transform","correct":"import { transform } from 'server-with-kill';"},{"note":"CommonJS require style for named export.","wrong":"const transform = require('server-with-kill');","symbol":"transform","correct":"const { transform } = require('server-with-kill');"},{"note":"The package ships TypeScript types; `transform` returns a `ServerWithKill` interface extending `http.Server`.","symbol":"ServerWithKill","correct":"import { ServerWithKill } from 'server-with-kill/dist/types/server-with-kill.d.ts'; // For type-only imports, though typically inferred"}],"quickstart":{"code":"import express from 'express';\nimport { transform } from 'server-with-kill';\nimport { Server } from 'http';\n\nconst app = express();\nconst PORT = 3000;\n\napp.get('/', (req, res) => {\n  res.send('Hello from server-with-kill! This server will be killed soon.');\n});\n\napp.get('/long-task', (req, res) => {\n  console.log('Received request for long-task...');\n  // Simulate a long-running process that might be interrupted by kill\n  setTimeout(() => {\n    res.send('Long task completed (if not killed)!');\n  }, 5000); \n});\n\nconst httpServer: Server = app.listen(PORT, () => {\n  console.log(`Server listening on http://localhost:${PORT}`);\n});\n\nconst serverWithKill = transform(httpServer);\n\nconsole.log('Server started. It will be forcibly killed in 3 seconds.');\n\nsetTimeout(() => {\n  serverWithKill.kill((err) => {\n    if (err) {\n      console.error('Error during server kill:', err.message);\n    } else {\n      console.log('Server killed and all active connections destroyed.');\n    }\n    process.exit(0);\n  });\n}, 3000);","lang":"typescript","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"Forcibly 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you pass your `http.Server` instance through the `transform` function: `const serverWithKill = transform(yourHttpServer);`","cause":"Attempting to call `.kill()` directly on a standard `http.Server` instance without first transforming it with `server-with-kill`.","error":"TypeError: server.kill is not a function"},{"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.","cause":"A client received a 'connection reset' error because the server forcibly closed the connection using `server.kill()` while the client was still active.","error":"Error: read ECONNRESET"}],"ecosystem":"npm"}