Skip to content

Deno module to check if a port is available, get an available TCP port, or kill a process running on a port.

License

Notifications You must be signed in to change notification settings

piyush-bhatt/deno-port

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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 licensed

About

Deno module to check if a port is available, get an available TCP port, or kill a process running on a port.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published