Gathering detailed insights and metrics for get-port
Gathering detailed insights and metrics for get-port
Gathering detailed insights and metrics for get-port
Gathering detailed insights and metrics for get-port
npm install get-port
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (95.19%)
TypeScript (4.81%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
908 Stars
67 Commits
65 Forks
14 Watchers
1 Branches
21 Contributors
Updated on Jul 08, 2025
Latest Version
7.1.0
Package Id
get-port@7.1.0
Unpacked Size
11.73 kB
Size
4.10 kB
File Count
5
NPM Version
9.2.0
Node Version
18.19.1
Published on
Mar 20, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
Get an available TCP port.
1npm install get-port
1import getPort from 'get-port'; 2 3console.log(await getPort()); 4//=> 51402
Pass in a preferred port:
1import getPort from 'get-port'; 2 3console.log(await getPort({port: 3000})); 4// Will use 3000 if available, otherwise fall back to a random port
Pass in an array of preferred ports:
1import getPort from 'get-port'; 2 3console.log(await getPort({port: [3000, 3001, 3002]})); 4// Will use any element in the preferred ports array if available, otherwise fall back to a random port
Use the portNumbers()
helper in case you need a port in a certain range:
1import getPort, {portNumbers} from 'get-port'; 2 3console.log(await getPort({port: portNumbers(3000, 3100)})); 4// Will use any port from 3000 to 3100, otherwise fall back to a random port
Returns a Promise
for a port number.
Type: object
Type: number | Iterable<number>
A preferred port or an iterable of preferred ports to use.
Type: Iterable<number>
Ports that should not be returned.
You could, for example, pass it the return value of the portNumbers()
function.
Type: string
The host on which port resolution should be performed. Can be either an IPv4 or IPv6 address.
By default, it checks availability on all local addresses defined in OS network interfaces. If this option is set, it will only check the given host.
Generate port numbers in the given range from
...to
.
Returns an Iterable
for port numbers in the given range.
Type: number
The first port of the range. Must be in the range 1024
...65535
.
Type: number
The last port of the range. Must be in the range 1024
...65535
and must be greater than from
.
Clear the internal cache of locked ports.
This can be useful when you want the results to be unaffected by previous calls.
Please note that clearing the cache could cause race conditions.
1import getPort, {clearLockedPorts} from 'get-port'; 2 3const port = [3000, 3001, 3002]; 4 5console.log(await getPort({port})); 6//=> 3000 7 8console.log(await getPort({port})); 9//=> 3001 10 11// If you want the results to be unaffected by previous calls, clear the cache. 12clearLockedPorts(); 13 14console.log(await getPort({port})); 15//=> 3000
There is a very tiny chance of a race condition if another process starts using the same port number as you in between the time you get the port number and you actually start using it.
Race conditions in the same process are mitigated against by using a lightweight locking mechanism where a port will be held for a minimum of 15 seconds and a maximum of 30 seconds before being released again.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 13/30 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More