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 🙏

© 2025 – Pkg Stats / Ryan Hefner

blockaid

v1.1.2

Published

Require that a port is listening, not listening, or kill if listening

Downloads

8,521

Readme

blockaid

npm version

blockaid is a lightweight, single-dependency CLI tool for orchestrating npm scripts. It helps you build reliable, OS-agnostic development and build workflows by making assertions about network ports.

Use Cases

blockaid is useful when your scripts depend on other processes, such as a database, a local API, or a development server.

  1. Ensure a database is running: Before starting your application, guarantee that a database (like MySQL on port 3306) is ready to accept connections.
  2. Prevent port conflicts: Before starting a development server, ensure the target port is free to avoid EADDRINUSE errors.
  3. Automate server restarts: Kill an existing process on a port before starting a new one, streamlining scripts that restart or reload.

All checks are performed in a cross-platform way, so your package.json scripts work seamlessly on Windows, macOS, and Linux.

Example Usage

1. Requiring a Dependent Service

If your server.js script depends on a MySQL database, you can require that an application is listening on port 3306 before proceeding:

"scripts": {
  "dev": "blockaid -r mysql:3306 && nodemon server.js"
}

If no application is listening on port 3306, the script will exit with an error:

$ npm run dev
mysql is required, but is not listening on port 3306.

2. Requiring a Port to Be Free

To prevent port conflicts, you can require that a port is not in use before starting your server. This is useful for avoiding EADDRINUSE errors.

"scripts": {
  "dev": "blockaid -x webserver:3000 && nodemon server.js"
}

If an application is already listening on port 3000, blockaid will report it and exit:

$ npm run dev
port 3000 must be free, but a process (e.g. webserver) is already listening.

3. Killing an Existing Process

You can automatically kill any process listening on a given port before an action. This is common in development workflows where you want to ensure a clean start. blockaid waits for the kill signal to be sent and the process to terminate before exiting.

Here, we use an environment variable for the port and kill any existing listener:

"scripts": {
  "start-dev": "PORT=3000 blockaid -k dev-server:PORT && nodemon server.js"
}

If a process is found, blockaid issues a kill command and waits for it to complete:

$ npm run start-dev
port 3000 must be free, but a process (e.g. dev-server) is already listening. Killing process...
(nodemon starts successfully afterward)

The shell return value will always be 0 (success) or 1 (failure).

Command-Line Interface

| Flag | Alias | Description | | ------------------------- | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | --require-listening | -r | PROGRAM_NAME:PORTRequires that a process is listening at PORT. PROGRAM_NAME is used for more helpful error messages. | | --require-not-listening | -x | PROGRAM_NAME:PORTRequires that nothing is listening at PORT. PROGRAM_NAME is used in messages if the requirement is not met. | | --kill-if-listening | -k | PROGRAM_NAME:PORTIf a process is listening at PORT, blockaid will kill it and wait for it to exit before proceeding. PROGRAM_NAME is for display. |

The PORT portion of the PROGRAM_NAME:PORT pair can be a number to use directly, or an environment variable to look up (e.g. the literal myserver:PORT would check process.env.PORT's value).