Skip to content

Wait for a port to open, associate it to a process, without blocking the port

Notifications You must be signed in to change notification settings

davidmarkclements/portly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

portly

Wait for a port to open, associate it to a process, without blocking the port

Signature

portly(port, options) => Promise =>  pid
portly(port, options = {detailed:true}) => Promise => info

Usage

ES5:

var portly = require('portly')

portly(3000, {timeout: 5000})
  .then(function (pid) {
    console.log(pid, ' is using port 3000')
  })
  .catch(function (err) {
    console.error(err)
  })

ES6 + ES7:

import portly from 'portly'

async function discover(port) {
  const pid = await portly(port)
  return pid
}

try { 
  console.log(discover(3000))
} catch (e) {
  console.error(e)
}

Options

  • type 'tcp' | 'udp' - default 'tcp' - whether to look for a tcp or udp port
  • pollInterval - default 200 - interval between port checks
  • timeout - default Infinity - fail after given time
  • detailed - default false - supplied PID if false, or full lsof info object if true

Full info object supplies the following:

{ state, command, pid, user, fd, type, device, 'size/off', node, name }

Support

Node 0.10 to Node 5 inclusive supported.

OS X and Linux only for now. We use lsof to examine the ports and get information about processes. PR's very welcome for Windows support.

Thanks

About

Wait for a port to open, associate it to a process, without blocking the port

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published