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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gracefulize

v1.0.0

Published

minimal code to help Node.js HTTP server shut down gracefully

Readme

gracefulize

Why

A Node.js HTTP server object, once listening on a handle (e.g. a port number), is expected to take that "handle resource" for itself until it is closed.

Except when it doesn't.

Say you have a Node.js HTTP server in your server.js file, then start it, then stop it with Ctrl + C, that HTTP server can be killed together with the host process (the server.js process itself), but sometimes it doesn't cleanly release the aforementioned "handle resource". In my experience, most times it does, but it's plain annoying when it doesn't, e.g. when the resource is a unix- socket.

While there are "scientific" explanations for all this (when it does, and when not), they are beyond the scope of this document, the purpose of which is to explain why this module exists & how it should be used.

What this helper module does is to ensure when the main Node.js process terminates, (e.g. on SIGINT), it first politely asks the Node.js HTTP server to peacefully shutdown, then it waits until the Node.js HTTP server has properly done so before allowing the main Node.js process to finally terminate.

However, if the Node.js HTTP server fails to cooperate politely (e.g. it hangs trying to serve some unresponsive client, or deal with a cyclic I/O operation - you name it), then the main Node.js process can still be "coldly" terminated by sending subsequent SIGINT signals to it.

Hopefully this module provides an acceptable middle ground to properly exit a Node.js process parenting a Node.js HTTP server. If you find a use case where this module is inappropriate, please raise an issue so we could improve this documentation accordingly.

How

If you already have done something like this before:

let express = require('express');
let myServer = express.listen(3000, () => {
  console.log('server started at port 3000');
});

Then you only need to add 1 additional line now:

let express = require('express');
let myServer = express.listen(3000, () => {
  console.log('server started at port 3000');
});
// the following line is new
require('gracefulize')(myServer);

Please note that the above example uses ExpressJS, but it is essentially the same for Koa or any other Node.js-based HTTP server.

Do I need this?

  • If you have never implemented anything to ensure a graceful shutdown of your Node.js HTTP server for your server app before, then yes
  • Otherwise, probably not