npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-http-shutdown-manager

v0.1.0

Published

Class to provide for orderly shutdown of Node HTTP servers

Downloads

2

Readme

Build Status NPM Status

Overview

This library provides a class to coordinate an orderly shutdown for Node.js HTTP servers. It does so by tracking the open connections and requests, and when a shutdown is requested, it closes connections with no open requests and closes other connections once all requests are complete.

Note that in case a request is stuck, you should always have a timeout on your shutdowns. Consider using node-shutdown-events to provide for a clean way to hook into the shutdown chain.

This was inspired by code from JoshuaWise.

Examples of use:

var HttpShutdownManager = require("node-http-shutdown-manager");
var http = require("http");

// Option 1 - let the ShutdownManager create the server
var mgr = new HttpShutdownManager();
var svr = mgr.server;

// Option 2 - create it yourself
var svr = http.createServer();
var mgr = new HttpShutdownManager(svr);

// When ready to shutdown...
mgr.shutdown(function() { console.log("HTTP server cleanly shutdown") });

// To use the promise:
mgr.shutdown()
.then(function() { console.log("HTTP server cleanly shutdown") });

// To use with node-shutdown-events:
process.on("shutdown", mgr.shutdown.bind(mgr));

API

new HttpShutdownManager(http = http.createServer())

Creates a new shutdown manager for the specified server.

  • If no server is specified, one is created - the server can be accessed at .server
  • You must do this before you start listening on the server

Member variables of public interest:

  • server: Server being managed
  • numOpenConnections - Number of currently open connections to the server
  • numOpenRequests - Number of currently open requests to the server
  • totalConnections - Total number of connections opened against the server (includes currently open connections)
  • totalRequests - Total number of requests submitted to the server (includes pending requests)

reset()

Resets total counts for the server

shutdown(cb)

Closes the server and proceedes to start closing connections. Once all connections are closed, the callback is called.

Returns a promise that is resolved when all connections are closed.

Contributing

Any PRs are welcome but please stick to following the general style of the code and stick to CoffeeScript. I know the opinions on CoffeeScript are...highly varied...I will not go into this debate here - this project is currently written in CoffeeScript and I ask you maintain that for any PRs.