portu
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

portu npm

Port utils.

Install

$ yarn add portu

Usage

const isPortFree: (port: number, host: string) => Promise<boolean>

const getFreePort: (from: number, to: number, host: string) => Promise<number>

const getPortProcess: (port: number, host: string) => Promise<number | null>

const killPortProcess: (port: number, host: string) => Promise<number | null>

const waitForPort: (port: number, host: string) => Promise<void>
import { isPortFree, getFreePort, getPortProcess, killPortProcess, waitForPort } from 'portu'

const host = 'localhost'
const port = 31337

const isFree = await isPortFree(port, host)
// true

const port = await getFreePort(port, port + 10, host
// 31337

let pid = await getPortProcess(port, host)
// null

pid = await killPortProcess(port, host)
// null

await waitForPort(port, host)
// checks every 200ms

Package Sidebar

Install

npm i portu

Weekly Downloads

2

Version

0.3.0

License

MIT

Unpacked Size

7.97 kB

Total Files

16

Last publish

Collaborators

  • deepsweet
  • psxcode
  • fosimus