Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
server-destroy
Advanced tools
The server-destroy npm package provides a simple way to add a destroy method to a Node.js HTTP server, allowing for the immediate termination of all active connections. This is particularly useful for gracefully shutting down servers during development or in production environments.
Add destroy method to server
This feature allows you to add a destroy method to a Node.js HTTP server. The code sample demonstrates how to create an HTTP server, enable the destroy method, and then destroy the server after 5 seconds.
const http = require('http');
const enableDestroy = require('server-destroy');
const server = http.createServer((req, res) => {
res.end('Hello, world!');
});
// Enable the destroy method on the server
enableDestroy(server);
server.listen(3000, () => {
console.log('Server is listening on port 3000');
});
// Destroy the server after 5 seconds
setTimeout(() => {
server.destroy(() => {
console.log('Server destroyed');
});
}, 5000);
The graceful-server package provides a way to gracefully shut down a Node.js server by handling open connections and requests. Unlike server-destroy, which immediately terminates all connections, graceful-server allows for a more controlled shutdown process, ensuring that ongoing requests are completed before the server is closed.
The http-terminator package offers a way to gracefully terminate HTTP and HTTPS servers in Node.js. It ensures that all active connections are properly closed before shutting down the server. Compared to server-destroy, http-terminator provides more options for handling ongoing requests and connections, making it a more flexible solution for graceful shutdowns.
Enable destroying a server, and all currently open connections.
var enableDestroy = require('server-destroy');
var server = http.createServer(function(req, res) {
// do stuff, blah blah blah
});
server.listen(PORT);
// enhance with a 'destroy' function
enableDestroy(server);
// some time later...
server.destroy();
FAQs
Enable destroying a server, and all currently open connections.
The npm package server-destroy receives a total of 1,262,824 weekly downloads. As such, server-destroy popularity was classified as popular.
We found that server-destroy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.