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

in-a-storm

v1.0.0

Published

Find a port to run your server on.

Readme

In A Storm

Finds a port to bind your server to. 'In A Storm' is inspired by (and some code has been taken from) find-and-bind, but gives you more ways of specifying what port(s) you want, and uses promises rather than node style callbacks.

$ npm install in-a-storm

Usage

'In A Storm' provides a listen function that is designed to work with any server that exposes the same interface as the node net.Server class. It returns a promise that will be fulfilled with the port number it is listening on.


var listen = require('in-a-storm');

listen(app).then(function(port) {
	console.log('Listening on port', port);
});

// or....

listen(app).then(function(port) {
	console.log('Listening on port', port);
}).catch(function(err) {
	console.error('Something weird happened and I was unable to bind to any port at all : ' + err);
});

It will select an unused port, and bind your app to it.

If your app is an instance of http.Server, it will try the port in the environment variable PORT first, then it will try port 80, then it will try port 8080 before trying a port at random.

If your app is an instance of https.Server, it will try 443, then 8443 before a random port.

Specifying the ports to use

There are a number of ways to specify preferences for ports to use.


// try port 8080, if that fails, select a random port.
listen(server, 8080);
listen(server, "8080");

// try port 8080, then 8081, then 8082, then if that fails, select a random port.
listen(server, "8080-8082");

// try port 80, then port 8080, then port 1000, then port 1001, then 1002, then a random port.
listen(server, [80, 8080, "1000-1002"]);

// bind to a specific host address 'myhost' with backlog.
listen(server, [80, 8080, "1000-1002"], 'myhost', backlog);

Compatible Servers

All servers that behave like net.Server will work.

To work correctly, the listen functions first argument must be the port to bind to and it must emit a 'listening' event when the port is successfully bound. It should also emit an error event if the port cannot be bound. If the port is set to 0, then a random available port must be chosen. In order for in-a-storm to find out which port has been chosen, the server must provide a .address() method providing a result with the port on it.

If you call the listen function with a function instead of a server object, it is assumed that this is an http handler like an express app, and an http server is created for it.

Future Work

The tests are mainly just modified versions of what find-and-bind does, so more work is needed there.

There might well be other sensible default behaviours that can be added based on the instance of the server.