{"name":"get-port","version":"7.2.0","description":"Get an available port","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/get-port.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=16"},"scripts":{"test":"xo && ava && tsd"},"keywords":["port","find","finder","portfinder","free","available","connection","connect","open","net","tcp","scan","random","preferred","chosen"],"devDependencies":{"@types/node":"^20.2.5","ava":"^5.3.0","tsd":"^0.28.1","xo":"^0.54.2"},"gitHead":"efbebfb0a2904b55d5ce9ab0badb52b3fbab99fe","types":"./index.d.ts","_id":"get-port@7.2.0","bugs":{"url":"https://github.com/sindresorhus/get-port/issues"},"homepage":"https://github.com/sindresorhus/get-port#readme","_nodeVersion":"25.8.0","_npmVersion":"11.11.0","dist":{"integrity":"sha512-afP4W205ONCuMoPBqcR6PSXnzX35KTcJygfJfcp+QY+uwm3p20p1YczWXhlICIzGMCxYBQcySEcOgsJcrkyobg==","shasum":"db0d52eb2d89890cdc010ed0e9a6f2d4b78cbbe7","tarball":"http://registry-npm.ywwl.com/get-port/download/get-port-7.2.0.tgz","fileCount":5,"unpackedSize":14428,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC2TXPsey/qXo8eASCPBkZxooHFvyucCqpbXpfxRNhPdQIgdsQfWRuSjtwIwgrq+kpeks2mh3sL2GgkaMV74Se2hkE="}],"size":4846,"noattachment":false,"key":"/get-port/-/get-port-7.2.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/get-port_7.2.0_1774158768941_0.8626599181982038"},"_hasShrinkwrap":false,"readme":"# get-port\n\n> Get an available [TCP port](https://en.wikipedia.org/wiki/Port_(computer_networking)).\n\n## Install\n\n```sh\nnpm install get-port\n```\n\n## Usage\n\n```js\nimport getPort from 'get-port';\n\nconsole.log(await getPort());\n//=> 51402\n```\n\nPass in a preferred port:\n\n```js\nimport getPort from 'get-port';\n\nconsole.log(await getPort({port: 3000}));\n// Will use 3000 if available, otherwise fall back to a random port\n```\n\nPass in an array of preferred ports:\n\n```js\nimport getPort from 'get-port';\n\nconsole.log(await getPort({port: [3000, 3001, 3002]}));\n// Will use any element in the preferred ports array if available, otherwise fall back to a random port\n```\n\nUse the `portNumbers()` helper in case you need a port in a certain range:\n\n```js\nimport getPort, {portNumbers} from 'get-port';\n\nconsole.log(await getPort({port: portNumbers(3000, 3100)}));\n// Will use any port from 3000 to 3100, otherwise fall back to a random port\n```\n\n## API\n\n### getPort(options?)\n\nReturns a `Promise` for a port number.\n\n#### options\n\nType: `object`\n\n##### port\n\nType: `number | Iterable<number>`\n\nA preferred port or an iterable of preferred ports to use.\n\n##### exclude\n\nType: `Iterable<number>`\n\nPorts that should not be returned.\n\nYou could, for example, pass it the return value of the `portNumbers()` function.\n\n##### reserve\n\nType: `boolean`\\\nDefault: `false`\n\nReserve the port so that it's locked for the lifetime of the process instead of the default 15-30 seconds.\n\nThis is useful when there is a long delay between getting the port and actually binding to it, such as in long-running test suites.\n\nReserved ports are locked globally by port number for the current process, even if you looked them up with a specific `host` or `ipv6Only` option.\n\nUse [`clearLockedPorts()`](#clearlockedports) to release reserved ports.\n\n##### host\n\nType: `string`\n\nThe host on which port resolution should be performed. Can be either an IPv4 or IPv6 address.\n\nBy default, it checks availability on all local addresses defined in [OS network interfaces](https://nodejs.org/api/os.html#os_os_networkinterfaces). If this option is set, it will only check the given host.\n\n### portNumbers(from, to)\n\nGenerate port numbers in the given range `from`...`to`.\n\nReturns an `Iterable` for port numbers in the given range.\n\n```js\nimport getPort, {portNumbers} from 'get-port';\n\nconsole.log(await getPort({port: portNumbers(3000, 3100)}));\n// Will use any port from 3000 to 3100, otherwise fall back to a random port\n```\n\n#### from\n\nType: `number`\n\nThe first port of the range. Must be in the range `1024`...`65535`.\n\n#### to\n\nType: `number`\n\nThe last port of the range. Must be in the range `1024`...`65535` and must be greater than `from`.\n\n### clearLockedPorts()\n\nClear the internal cache of locked ports, including any ports locked with the [`reserve`](#reserve) option.\n\nThis can be useful when you want the results to be unaffected by previous calls.\n\nPlease note that clearing the cache removes protection against [in-process race conditions](#beware).\n\n```js\nimport getPort, {clearLockedPorts} from 'get-port';\n\nconst port = [3000, 3001, 3002];\n\nconsole.log(await getPort({port}));\n//=> 3000\n\nconsole.log(await getPort({port}));\n//=> 3001\n\n// If you want the results to be unaffected by previous calls, clear the cache.\nclearLockedPorts();\n\nconsole.log(await getPort({port}));\n//=> 3000\n```\n\n## Beware\n\nThere 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.\n\n**In-process race conditions** (such as when running parallel Jest tests) are completely eliminated by a lightweight locking mechanism where returned ports are held for 15-30 seconds before being eligible for reuse. If the delay between getting a port and binding to it may exceed this window (for example, in long-running test suites), use the [`reserve`](#reserve) option to lock the port for the lifetime of the process.\n\n**Multi-process race conditions** are extremely rare and will result in an immediate `EADDRINUSE` error when attempting to bind to the port, allowing your application to retry.\n\n## Related\n\n- [get-port-cli](https://github.com/sindresorhus/get-port-cli) - CLI for this module\n","publish_time":1774158769076,"_cnpm_publish_time":1774158769076,"dist-tags":{"latest":"7.2.0"}}