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