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

pick-port

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

$ npm install pick-port

Usage

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

Get a random UDP port in IP 0.0.0.0:

const port = await pickPort();

Get a TCP port in a specific IP and port range:

const port = await =
	pickPort({ type: 'tcp', ip: '192.168.10.111', minPort: 8000, maxPort: 9000 })

API

await pickPort({ type, ip, minPort, maxPort, reserveTimeout })

Async function. Resolves with an available port or rejects with an error otherwise.

OptionTypeDescriptionRequiredDefault
typeString'udp' or 'tcp'.No'udp'
ipStringIPv4 or IPv6 address for which a free port is requested.No'0.0.0.0'
minPortNumberMinimum port.No10000
maxPortNumberMaximum port.No20000
reserveTimeoutNumberTimeout in seconds during which a returned port will be internally reserved and prevented of being returned on a future call before the timeout has elapsed.No5
  • @returns {Number} A free port.

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

Author

  • José Luis Millán [github]

License

ISC

Keywords

FAQs

Package last updated on 19 Jun 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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc