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

find-free-port-sync

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-free-port-sync

Find free port synchronously without callback

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19K
decreased by-1.05%
Maintainers
1
Weekly downloads
 
Created
Source

Description

Find free port synchronously, useful when you need to get the port directly without callback.

Like config webpack-dev-server with port automatically.

module.exports = {
    ...
    output: '...',
    devServer: {
        ...
        port: "a free port"
    }
};

Installation

npm install find-free-port-sync --save-dev

Options

start

type: number | default: 1

Start of range to find, should be greater than 0

end

type: number | default: 65534

End of range to find, should be less than 65535

num

type: number | default: 1

Number of ports to find, relates to the return value

  • When num === 1, return a free random port if found, null if not
  • When num > 1, return an array of free [port] orderly if found, empty array [] if not

ip

type: string | default: 0.0.0.0|127.0.0.1

It will scan local adress by default, specify an ip here

port

type: number | default: null

If port is defined, it will return whether the port is free around start end ip option

Examples

Find a free port for local address

let findFreePort = require('find-free-port-sync');

let port = findFreePort();

Find 10 free ports between 10000 and 30000 for 192.168.1.1

let findFreePort = require('find-free-port-sync');

let port = findFreePort({
    start: 10000,
    end: 30000,
    num: 10,
    ip: '192.168.1.1'
});

Check if a port is free

let findFreePort = require('find-free-port-sync');

let portIsOk = findFreePort({
    port: 12345
});

Keywords

FAQs

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