Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/piyush-bhatt/deno-port
Deno module to check if a port is available, get an available TCP port, or kill a process running on a port.
https://github.com/piyush-bhatt/deno-port
deno port tcp typescript
Last synced: 18 days ago
JSON representation
Deno module to check if a port is available, get an available TCP port, or kill a process running on a port.
- Host: GitHub
- URL: https://github.com/piyush-bhatt/deno-port
- Owner: piyush-bhatt
- License: mit
- Created: 2021-01-22T11:13:45.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-28T21:58:08.000Z (about 3 years ago)
- Last Synced: 2025-01-16T23:08:43.676Z (30 days ago)
- Topics: deno, port, tcp, typescript
- Language: TypeScript
- Homepage: https://deno.land/x/port
- Size: 6.84 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deno-port
> Deno module to check if a port is available, get an available TCP port, or kill a process running on a port.
### Import Module
```typescript
import {
getAvailablePort,
getAvailablePortSync,
isPortAvailable,
isPortAvailableSync,
killProcessOnPort
} from "https://deno.land/x/port/mod.ts"
```## Usage
### isPortAvailable(options)
_Requires `--allow-net` flag_\
Returns a promise which resolves to `true` if a given port is available, else `false`.### isPortAvailableSync(options)
_Requires `--allow-net` flag_\
Returns `true` if a given port is available, else `false`.#### options
Type: `object`##### port
_Required_\
Type: `number`##### hostname
Type: `string`##### transport
Type: `string`\
Values: `tcp`---
### getAvailablePort(options)
_Requires `--allow-net` flag_\
Returns a promise which resolves to an available port number based on the options provided.### getAvailablePortSync(options)
_Requires `--allow-net` flag_\
Returns an available port number based on the options provided.#### options
Type: `object`##### port
Type: `number[] | { start: number, end: number }`\
If not provided, a random port will be returned\
If an array of ports is provided, the first encountered available port in the array will be returned\
If a range is provided, the first encountered available port in the range will be returned##### hostname
Type: `string`##### transport
Type: `string`\
Values: `tcp`---
### killProcessOnPort(port)
_Requires `--allow-run` and `--allow-net` flag_\
Kills the process running on the given port. Returns `true` if the process is killed successfully and the port is free, else `false`.#### port
_Required_\
Type: `number`## Test
>deno test --allow-net mode_test.ts
## Licensing
[MIT](https://github.com/piyush-bhatt/deno-port/blob/main/LICENSE) licensed