porthog

1.0.1 • Public • Published

porthog

This module identifies which application is using a specified port, providing the process name and PID. Works for Windows, OSX, and most flavors of Linux/Unix that support the lsof, ss, or netstat operations.

OSX & Linux
Windows

CLI Implementation

npm install -g porthog

porthog 33649 80

Outputs:

PORT      PID       PROCESS
--------------------------------------------------
33649     43580     node-webkit Helper (cbutler)
80        -         -

API Implementation Example

const porthog = require('porthog')
const data = porthog(80)
 
console.log(data.user, 'is running', data.process + ' (PID ' + data.pid + ') on port 80.')
 
// Output
// cbutler is running node.exe (PID 656) on port 80.

This operation may require elevated/root privileges.

Uses

We're using this in Fenix Web Server to resolve port conflicts. When a user tries to launch a server on an occupied port, we use porthog to determine which app is "hogging" the port and provide the user an option to stop/kill the offending process.

We also use this in combination with node-windows, node-mac, and node-linux to create background processes that monitor ports and notify users what's running on the ports they want to use.

There are certainly many other uses. If you use this, be warned that some operating systems (Windows in particular) may require elevated permissions. This is dependent on each user's environment, so it's not always predictable. To get around this, we've found the aforementioned node-* modules to be useful when creating daemons (especially the binary utilities and extra scripts for Windows). For Electron/NW.js apps, sudo-prompt has been quite helpful.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i porthog

Weekly Downloads

50

Version

1.0.1

License

MIT

Unpacked Size

11.4 kB

Total Files

6

Last publish

Collaborators

  • cbutler