{"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.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install server-with-kill"],"cli":null},"imports":["import { transform } from 'server-with-kill';","const { transform } = require('server-with-kill');","import { ServerWithKill } from 'server-with-kill/dist/types/server-with-kill.d.ts'; // For type-only imports, though typically inferred"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}