process-finder
Find processes using a simple API
Last updated 10 years ago by bevacqua .
Repository · Bugs · Original npm · Tarball · package.json
$ npm install process-finder 
SYNC missed versions from official npm registry.

process-finder

Find processes and watch ports for listener processes using a simple API

Installation

Using npm

$ npm install process-finder --save

#find(port, fn(err, pids, data, internal))

Finds processes listening on the provided port, invokes fn with an array of pids listening on that port.

data is the output of the command that checks the status of the port. internal will contain any internal errors that might have been suppressed.

#find Usage

var finder = require('process-finder');
var port = 3000;

finder.find(port, function(err, pids){
    // do something about the pids listening on the port, i.e:
    pids.forEach(process.kill);
});

Port can be an object of options, or just a port.

{
    port: 3000, // the port we listen on
    elevate: false, // whether to use `sudo`, to get elevated priviledges
}

#watch(port)

Returns an EventEmitter that allows us to track a port's listening processes.

Port can be an object of options, or just a port.

{
    port: 3000, // the port we listen on
    frequency: 200, // the frequency with which the port is scanned for changes
    elevate: false, // whether to use `sudo`, to get elevated priviledges
    info: false // if enabled, a verbose `info` event will be emitted
}

#watch Usage

var finder = require('process-finder');
var port = 3000; // port to watch
var watcher = finder.watch(port);

watcher.on('listen', function(pid){
    console.log(pid + ' listening on port ' + port);
});

watcher.on('unlisten', function(pid){
    console.log(pid + ' no longer listening on port ' + port);
});

watcher.on('error', console.error);
watcher.on('update', function(pids){
    console.log('updated! listeners:', pids);
});

#watch API

#watch.stop()

Stops a watch. It will no longer emit events.

#watch.start()

Starts a watch which was previously stopped using .stop()

#watch.restart()

Force-restart the watch.

#watch events

Watch extends the EventEmitter prototype, and provides a few events you can listen for.

#watch.on('start', fn())

Triggers when the watch is started, either when manually started, or when a new watch is created.

#watch.on('stop', fn())

Triggers when a watch is stopped.

#watch.on('listen', fn(pid))

Triggers when a pid is detected to be listening on the port we're watching. The pid is passed as an argument.

#watch.on('unlisten', fn(pid))

Triggers when a pid is detected to be no longer listening on the port we're watching. The pid is passed as an argument.

#watch.on('update', fn(pids))

Triggers every time the port is scanned for changes.

#watch.on('info', fn(data, internal))

data is the output of the command that checks the status of the port. internal will contain any internal errors that might have been suppressed.

#watch.on('error', fn(err))

Triggers whenever an error is thrown.

CLI

The CLI allows you to wait on a port

procfinder --wait --port 3000

Once a process starts listening on that port, the CLI will output its pid and exit.

Current Tags

  • 1.0.0                                ...           latest (10 years ago)

12 Versions

  • 1.0.0                                ...           10 years ago
  • 0.1.3                                ...           11 years ago
  • 0.1.2                                ...           11 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
  • 0.0.7                                ...           11 years ago
  • 0.0.6                                ...           11 years ago
  • 0.0.5                                ...           11 years ago
  • 0.0.4                                ...           11 years ago
  • 0.0.3                                ...           11 years ago
  • 0.0.2                                ...           11 years ago
  • 0.0.1                                ...           11 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE