Socket
Socket
Sign inDemoInstall

portfinder

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

portfinder

A simple tool to find an open port on the current machine


Version published
Weekly downloads
6.8M
decreased by-1.3%
Maintainers
2
Weekly downloads
 
Created

What is portfinder?

The portfinder npm package is a utility for getting a port number that is guaranteed to be free on the current machine. It is useful for running servers on dynamically assigned ports to avoid conflicts.

What are portfinder's main functionalities?

Get an available port

This feature allows you to find an available port on the machine. The `getPort` function takes a callback that provides the port number.

const portfinder = require('portfinder');

portfinder.getPort((err, port) => {
  if (err) {
    throw err;
  }
  console.log('Available port found:', port);
});

Set the base port

Before calling `getPort`, you can set the `basePort` property to tell portfinder to start searching for a free port from a certain number.

const portfinder = require('portfinder');

portfinder.basePort = 3000;
portfinder.getPort((err, port) => {
  if (err) {
    throw err;
  }
  console.log('Available port found:', port);
});

Set the range of ports to search

You can specify a range of ports for portfinder to search within by providing an options object with `port` and `stopPort` properties.

const portfinder = require('portfinder');

portfinder.getPort({
  port: 3000, // minimum port
  stopPort: 3333 // maximum port
}, (err, port) => {
  if (err) {
    throw err;
  }
  console.log('Available port found:', port);
});

Other packages similar to portfinder

Keywords

FAQs

Package last updated on 12 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc