Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-ports

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-ports

gets multiple open ports

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.8K
decreased by-11.46%
Maintainers
1
Weekly downloads
 
Created
Source

get-ports

stable

Finds multiple open ports after your specified base ports, and below the max range.

Unlike getport or get-port, this is useful for situations where you need multiple servers to run on open ports.

If not all ports could be found, the error callback is triggered.

Install

npm install get-ports --save

Example

The resulting ports array is parallel to your input (base) ports.

For example, if port 8000 and 9966 are already in use:

var getPorts = require('get-ports')

getPorts([ 8000, 9966 ], function (err, ports) {
  if (err) throw new Error('could not open servers')
  
  console.log(ports)
  //=> [ 8001, 9967 ]
})

Usage

NPM

getPorts(basePorts, [maxPort], callback)

For the given array of basePorts, tries to find the next available port from each one. This keeps track of available ports to ensure there are no conflicts in the final result.

If the finite number maxPort is specified, the portfinding will fail when it reaches that maximum port. Defaults to 60000.

The callback is called with (err, ports), where err will be an Error if any of the portfindings failed (i.e. no open ports within range). If successful, err will be null and ports will be an array, parallel to basePorts, with the found port numbers.

License

MIT, see LICENSE.md for details.

Keywords

FAQs

Package last updated on 15 Mar 2016

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc