Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

destroyable-server

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

destroyable-server

A tiny Node.js module to make any server force-closeable

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
86K
decreased by-2.82%
Maintainers
1
Weekly downloads
 
Created
Source

Destroyable-Server Build Status Available on NPM

Part of HTTP Toolkit: powerful tools for building, testing & debugging HTTP(S)

A tiny Node.js module to make any server force-closeable.

Without this module, when you call server.close() it stops listening for new connections, but it doesn't close existing connections, which can stop your process from exiting or cause problems with starting new servers.

With this module, you can call server.destroy() to forcibly shut down all existing sockets in addition to closing the server, to immediately & completely end all connections.

This works for HTTP, TLS, bare sockets, whatever. Anything that extends net.Server or follows its patterns should work correctly.

Use it like so:

const net = require('net');

const { makeDestroyable } = require('destroyable-server');

// Create a server somewhere:
let server = net.Server((socket) => { /* ... */ };

// Make it destroyable:
server = makeDestroyable(server);

// When you're done with it, destroy it:
server.destroy();

Calling makeDestroyable mutates the passed server slightly, to track all active connections, and add a destroy() method which ends them.

Calling destroy() ends the connections and the server, and returns a promise, which resolves once that is complete.

Keywords

FAQs

Package last updated on 30 Apr 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc