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
99.4
Supply Chain
99.5
Quality
76.8
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
877 Stars
67 Commits
64 Forks
15 Watching
1 Branches
21 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
JavaScript (95.19%)
TypeScript (4.81%)
Cumulative downloads
Total Downloads
Last day
-20.7%
1,503,421
Compared to previous day
Last week
-2.5%
9,888,566
Compared to previous week
Last month
5.6%
42,242,320
Compared to previous month
Last year
29.9%
460,980,104
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 dangerous workflow patterns detected
Reason
no binaries found in the repo
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
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
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 2024-11-18
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