Socket
Socket
Sign inDemoInstall

pick-port

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pick-port

Get a free TCP or UDP port for the given IP address


Version published
Weekly downloads
3.8K
increased by19.18%
Maintainers
1
Weekly downloads
 
Created
Source

Get an available TCP or UDP port for the given IP address.

Usage

const pickPort = require('pick-port');

pickPort()
	.then(port =>
	{
		console.log(port);
	});

Optionally, provide the TCP/IP protocol family type, IP address and/or port:

pickPort({ type: 'tcp', ip: '10.10.10.1', port: 8000 })
	.then(port =>
	{
		console.log(port);
	})
	.catch((error) =>
	{
		console.log(error);
	});

API

pickPort([options])

Returns a Promise.

Resolves with the free port number on success or throws if error or no free ports in the given range are available.

options

Type: Object

options.type

TCP/IP family type. Possible values for this parameter are 'udp' and 'tcp'.

  • Type: String.
  • Default value: 'udp'.
options.port

Specific port to be checked or 0 to specify that any free port can be taken.

  • Type: Number.
  • Default value: 0.
options.range

The port range for which a free port is requested. If specified, only ports in the given range are considered.

  • Type: Object.
  • Default value: undefined.
options.range.min

The minimum port number in the range.

  • Type: Number
options.range.max

The maximum port number in the range.

  • Type: Number.
options.ip

The IP address for which a free port is requested. IPv4 and IPv6 addressing is supported.

  • Type: String.
  • Default value: '127.0.0.1'.
options.reserveTimeout

Timeout in seconds, during which a returned free port will be internally reserved and prevented of being returned on a future call before the timeout has elapsed.

This provides the application using this library with the required time to bind the free port before it is given again on a future call.

  • Type: Number.
  • Default value: 5.

Keywords

FAQs

Package last updated on 17 Sep 2018

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