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

get-ports-natively

v1.0.13

Published

get ports using native OS commands

Readme

get-ports-natively

50x faster port finding with native OS commands. Works on Windows, macOS, and Linux.

A lightweight Node.js module that finds available network ports using native OS commands. Works on Windows, macOS, and Linux without any external dependencies.

Benchmarks

Most port-finding libraries rely on the net module and make checks one by one. If your goal is to just find the next open port, it's not a big deal to brute force it. However to get all used ports on the system, it's much more efficient to use native OS commands.

Running benchmarks...
net module took 2.04195045 seconds (2041.95045 milliseconds)
getUsedPorts took 0.040742905 seconds (40.742905 milliseconds)
Speed difference: 50X faster

Features

  • Get all used ports on your system
  • Find available ports within a specified range
  • Native OS commands for better performance
  • Platform-specific implementations (Windows, macOS, Linux)
  • Zero external dependencies
  • TypeScript support

Installation

npm install get-ports-natively

Usage

Find a Free Port

import {findFreePort} from 'get-ports-natively';

// Find the first available port starting from 3000
const port = await findFreePort();
console.log(`Found free port: ${port}`);

// Find a free port within a specific range
const customPort = await findFreePort(8000, 9000);
console.log(`Found free port in range: ${customPort}`);

Get All Used Ports

import {getUsedPorts} from 'get-ports-natively';

const usedPorts = await getUsedPorts();
console.log('Currently used ports:', [...usedPorts]);

API

findFreePort(startPort?: number, endPort?: number): Promise<number | null>

Finds the first available port within the specified range.

  • startPort (optional): Starting port number (default: 3000)
  • endPort (optional): Ending port number (default: 65535)
  • Returns: Promise resolving to the first available port, or null if none found

getUsedPorts(): Promise<Set<number>>

Gets all currently used ports on the system.

  • Returns: Promise resolving to a Set of used port numbers

Platform Support

  • Windows: Uses netstat with CMD commands
  • macOS: Uses netstat with awk
  • Linux: Uses netstat with awk

Requirements

  • Node.js >= 16

License

MPL-2.0

Contributing

Contributions are welcome! Feel free to open issues and pull requests.