{"id":16221543,"url":"https://github.com/zingerlittlebee/port-selector","last_synced_at":"2026-03-18T00:03:53.313Z","repository":{"id":37056050,"uuid":"486418249","full_name":"ZingerLittleBee/port-selector","owner":"ZingerLittleBee","description":"select port what you want for NodeJS power by Rust","archived":false,"fork":false,"pushed_at":"2023-01-08T17:08:43.000Z","size":549,"stargazers_count":12,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-14T16:04:49.518Z","etag":null,"topics":["nodejs","nodejs-library","port","rust"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/port-selector","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZingerLittleBee.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.config.js","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-28T02:24:02.000Z","updated_at":"2023-08-11T10:41:51.000Z","dependencies_parsed_at":"2023-02-08T06:45:18.884Z","dependency_job_id":null,"html_url":"https://github.com/ZingerLittleBee/port-selector","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Fport-selector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Fport-selector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Fport-selector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Fport-selector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZingerLittleBee","download_url":"https://codeload.github.com/ZingerLittleBee/port-selector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244416940,"owners_count":20449368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","nodejs-library","port","rust"],"created_at":"2024-10-10T12:08:42.662Z","updated_at":"2026-03-18T00:03:53.267Z","avatar_url":"https://github.com/ZingerLittleBee.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Language : 🇺🇸 English | [🇨🇳 简体中文](https://github.com/ZingerLittleBee/port-selector/blob/main/README.zh-CN.md)\n\n\u003ch1 align=\"center\"\u003eport-selector\u003c/h1\u003e\n\u003cdiv align=\"center\"\u003e\n\n[![NPM Version](https://img.shields.io/npm/v/port-selector)](https://www.npmjs.com/package/port-selector)\n[![NPM Downloads](https://img.shields.io/npm/dt/port-selector)](https://www.npmjs.com/package/port-selector)\n![Bundle Size](https://img.shields.io/bundlephobia/minzip/port-selector)\n\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n\n[![GitHub Actions CI](https://img.shields.io/github/workflow/status/ZingerLittleBee/port-selector/Test%20CI)](https://github.com/ZingerLittleBee/port-selector/actions)\n![License](https://img.shields.io/github/license/ZingerLittleBee/port-selector)\n\n\u003c/div\u003e\n\n## Overview\n\n`port-selector` is a cross-platform NodeJS library implemented in Rust. It mainly provides port availability checking and filtering ports based on filter conditions.\n\n## Getting Started\n### Prerequisites\n- [Node.js](https://nodejs.org) (\u003e= 10.0.0 required, LTS preferred)\n### Installation\n```bash\nnpm install port-selector\n# or\nyarn add port-selector\n# or\npnpm i port-selector\n```\n\n```ts\nimport {\n    Selector,\n    isFree,\n    isFreeTcp,\n    isFreeUdp,\n    randomFreePort,\n    randomFreeTcpPort,\n    randomFreeUdpPort,\n    selectFreePort,\n    selectFromGivenPort\n} from 'port-selector'\n```\n\n## Goods\n[isFree](#isfree) · [isFreeTcp](#isfreetcp) · [isFreeUdp](#isfreeudp) · [randomFreePort](#randomfreeport) · [randomFreeTcpPort](#randomfreetcpport) · [randomFreeUdpPort](#randomfreeudpport) · [selectFromGivenPort](#selectfromgivenport) · [selectFreePort](#selectfreeport)\n\n\n## Documentation\n\n### `isFree`\nCheck whether the port is not used on TCP and UDP\n```ts\nfunction isFree(port: number): boolean\n```\n\n### `isFreeTcp`\nCheck whether the port is not used on TCP\n```ts\nfunction isFreeTcp(port: number): boolean\n```\n\n### `isFreeUdp`\nCheck whether the port is not used on UDP\n```ts\nfunction isFreeUdp(port: number): boolean\n```\n\n### `randomFreePort`\nThe system randomly assigns available TCP and UDP ports\n```ts\nfunction randomFreePort(): number\n```\n\n### `randomFreeTcpPort`\nThe system randomly assigns available TCP ports\n```ts\nfunction randomFreeTcpPort(): number\n```\n\n### `randomFreeUdpPort`\nThe system randomly assigns available UDP ports\n```ts\nfunction randomFreeUdpPort(): number\n```\n\n### `selectFromGivenPort`\nCheck from `starterPort` and return the first available port\n\nReturn if `starterPort` is available; Otherwise `starterPort += 1` until the port is available\n```ts\nfunction selectFromGivenPort(starterPort: number): number\n```\n\n### `selectFreePort`\nGets a matching port based on the `Selector` parameter constraint\n```ts\nfunction selectFreePort(selector?: Selector): number\n```\n\n```ts\nexport type Selector = {\n    // Check whether the port is available on TCP.\n    // The default value is true.\n    checkTcp?: boolean\n    // Check whether the port is available on UDP.\n    // The default value is true.\n    checkUdp?: boolean\n    // Set the generated port range, starting value\n    // The default value is 0.\n    portFrom?: number\n    // Set the generated port range, end value\n    // The default value is 65535.\n    portTo?: number\n    // Maximum number of random times. Default value: 100\n    // If no available port number is found within the maximum random number of loops, None is returned\n    maxRandomTimes?: number\n}\n```\n\n## Thanks\n[napi-rs](https://github.com/napi-rs/napi-rs)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzingerlittlebee%2Fport-selector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzingerlittlebee%2Fport-selector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzingerlittlebee%2Fport-selector/lists"}