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

wait-port-now

v1.0.0

Published

Wait until a TCP port is open. Zero dependencies. Node.js + CLI.

Readme

wait-port-now

npm version npm weekly downloads license node version

Wait until a TCP port is open. Zero dependencies. Works in Node.js + CLI.


Install

Install locally as a development dependency:

npm install --save-dev wait-port-now

Or run on-demand via npx:

npx wait-port-now 3000

Programmatic API

wait-port-now distributes both native ESM and CommonJS wrappers.

ESM / TypeScript Example

import { waitForPort, TimeoutError } from 'wait-port-now';

async function start() {
  try {
    // Wait for port 5432 with custom options
    await waitForPort(5432, {
      host: 'localhost',
      timeout: 10000, // 10 seconds timeout
      interval: 500   // poll every 500ms
    });
    console.log('Database is ready! Starting application...');
  } catch (err) {
    if (err instanceof TimeoutError) {
      console.error(`Timeout! Port ${err.port} on ${err.host} was not ready within ${err.timeout}ms.`);
    } else {
      console.error('An unexpected error occurred:', err);
    }
  }
}

start();

CommonJS / JavaScript Example

const { waitForPort, TimeoutError } = require('wait-port-now');

async function check() {
  try {
    // Basic usage (defaults to localhost, 30s timeout, 250ms interval)
    await waitForPort(3000);
    console.log('Server is up!');
  } catch (err) {
    if (err instanceof TimeoutError) {
      console.error('Connection timed out');
    }
  }
}

check();

CLI Usage

Usage: wait-port-now <port> [options] [-- <command> [args...]]

Options:
  --host <host>       Host to check (default: localhost)
  --timeout <ms>      Timeout in ms (default: 30000)
  --interval <ms>     Poll interval in ms (default: 250)
  -h, --help          Show help
  -v, --version       Show version

Real-world CLI Examples

1. Wait for PostgreSQL before running migrations (CI/CD Pipelines)

wait-port-now 5432 --timeout 60000 -- npm run db:migrate

2. Wait for a dev server before running Playwright tests (E2E testing)

wait-port-now 3000 -- npx playwright test

3. Wait for Redis before starting a worker (Docker Compose startup)

wait-port-now 6379 --host redis --node worker.js

Options Table

| Option | Type | Default | Description | |--------|------|---------|-------------| | host | string | 'localhost' | Hostname or IP address to connect to | | timeout | number | 30000 | Maximum time to wait in milliseconds before throwing a TimeoutError | | interval | number | 250 | Sleep time in milliseconds between connection retries |


Comparison Table

| Feature | wait-port-now | wait-on | wait-port | |---------|-----------------|-----------|-------------| | Zero dependencies | ✅ | ❌ | ❌ | | TypeScript types | ✅ | ✅ | ❌ | | ESM + CJS | ✅ | ❌ | ❌ | | Node 18+ | ✅ | ✅ | ✅ | | File/HTTP wait | ❌ | ✅ | ❌ |


How It Works

wait-port-now uses Node's native node:net module to perform a raw TCP socket connection check.

  • It attempts a TCP handshake with the target host and port.
  • If the connection succeeds, it cleans up and releases the socket immediately to prevent connection leaks.
  • If it encounters a connection error (like ECONNREFUSED or ENOTFOUND), it waits for the configured interval and retries.
  • If the total elapsed time exceeds the timeout, it throws a custom TimeoutError.

License

MIT © 2025 [Your Name]