Find processes occupying a given port
lsofi 

Rationale
lsof -i :<port> for unix, darwin and win32 alike
Installation
npm install --save lsofi
Usage
ESM
import lsofi from 'lsofi'
const occupied = await lsofi(1337)
const free = await lsofi(1338)
console.log(occupied, free)
// => 9834 null
CommonJS
const lsofi = require('lsofi')
const occupied = await lsofi(1337)
const free = await lsofi(1338)
console.log(occupied, free)
// => 9834 null
Migration Notes
- Minimum supported Node.js version is now
20.0.0.
- Package now ships dual entry points using
exports:
import lsofi from 'lsofi' (ESM)
require('lsofi') (CommonJS compatibility)
- Runtime dependencies removed:
is-number: replaced with native Number() and Number.isFinite() validation.
through2: replaced with native stream parsing via readline.
See also
- krampus - Kill processes occupying a given port
lsofi is built by marionebl and contributors. It is released under the MIT license.