15815213711
2024-08-26 67b8b6731811983447e053d4396b3708c14dfe3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/// <reference types="node"/>
import {ListenOptions} from 'net';
 
declare namespace getPort {
    interface Options extends Omit<ListenOptions, 'port'> {
        /**
        A preferred port or an iterable of preferred ports to use.
        */
        readonly port?: number | Iterable<number>;
 
        /**
        The host on which port resolution should be performed. Can be either an IPv4 or IPv6 address.
        */
        readonly host?: string;
    }
}
 
declare const getPort: {
    /**
    Get an available TCP port number.
 
    @returns Port number.
 
    @example
    ```
    import getPort = require('get-port');
 
    (async () => {
        console.log(await getPort());
        //=> 51402
 
        // Pass in a preferred port
        console.log(await getPort({port: 3000}));
        // Will use 3000 if available, otherwise fall back to a random port
 
        // Pass in an array of preferred ports
        console.log(await getPort({port: [3000, 3001, 3002]}));
        // Will use any element in the preferred ports array if available, otherwise fall back to a random port
    })();
    ```
    */
    (options?: getPort.Options): Promise<number>;
 
    /**
    Make a range of ports `from`...`to`.
 
    @param from - First port of the range. Must be in the range `1024`...`65535`.
    @param to - Last port of the range. Must be in the range `1024`...`65535` and must be greater than `from`.
    @returns The ports in the range.
 
    @example
    ```
    import getPort = require('get-port');
 
    (async () => {
        console.log(await getPort({port: getPort.makeRange(3000, 3100)}));
        // Will use any port from 3000 to 3100, otherwise fall back to a random port
    })();
    ```
    */
    makeRange(from: number, to: number): Iterable<number>;
};
 
export = getPort;