pidusage vs ps-list vs ps-node
Process Monitoring and Management in Node.js
pidusageps-listps-nodeSimilar Packages:

Process Monitoring and Management in Node.js

pidusage, ps-list, and ps-node are utilities for interacting with system processes in Node.js applications. pidusage focuses on retrieving CPU and memory statistics for a specific process ID (PID). ps-list provides a modern, cross-platform way to list all running processes with detailed metadata. ps-node offers process lookup and management capabilities, primarily designed for Unix-like systems, allowing developers to find processes by arguments or kill them. Together, they cover the spectrum from monitoring resource usage to managing process lifecycles.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
pidusage054636 kB23a year agoMIT
ps-list0287504 kB4a year agoMIT
ps-node0131-289 years agoMIT

Process Monitoring and Management in Node.js

When building system tools, dashboards, or backend services in Node.js, you often need to interact with the operating system's process table. Whether you are monitoring resource usage, finding a specific service, or managing child processes, choosing the right tool matters. pidusage, ps-list, and ps-node solve different parts of this problem. Let's compare how they handle process data, platform support, and API design.

🎯 Scope: Single Process Stats vs Full System List

pidusage focuses on a single Process ID.

  • It returns detailed CPU and memory statistics for that specific PID.
  • Best for monitoring the health of your own app or a known child process.
// pidusage: Get stats for a specific PID
const pidusage = require('pidusage');

pidusage.stat(process.pid, (err, stats) => {
  if (err) throw err;
  console.log(`CPU: ${stats.cpu}%`);
  console.log(`Memory: ${stats.memory} bytes`);
});

ps-list retrieves a list of all running processes.

  • It returns an array of process objects with basic info like name and PID.
  • Best for system-wide scans or finding a process by name.
// ps-list: List all processes
const psList = require('ps-list');

(async () => {
  const processes = await psList();
  console.log(`Total processes: ${processes.length}`);
  console.log(processes[0]); // { pid, name, cpu, memory, ... }
})();

ps-node looks up processes based on query criteria.

  • It filters the process list by arguments or properties.
  • Best for finding a specific service running with certain flags.
// ps-node: Lookup process by arguments
const ps = require('ps-node');

ps.lookup({ command: 'node', arguments: 'app.js' }, (err, resultList) => {
  if (err) throw err;
  resultList.forEach(process => {
    console.log(`Found PID: ${process.pid}`);
  });
});

πŸ–₯️ Platform Support: Windows vs Unix

pidusage works consistently across major OSs.

  • Handles differences between Windows and Unix internally.
  • You write one code path for all environments.
// pidusage: Cross-platform stats
// Works on Windows, Linux, macOS without changes
pidusage.stat(1234, (err, stats) => {
  // stats.pid, stats.cpu, stats.memory available everywhere
});

ps-list is built for cross-platform compatibility.

  • Uses native OS commands under the hood but normalizes output.
  • Safe for tools that must run on developer laptops (macOS/Windows) and servers (Linux).
// ps-list: Cross-platform listing
// Returns consistent property names across OS
const list = await psList();
// list[0].name is always a string, regardless of OS

ps-node is primarily designed for Unix-like systems.

  • Relies on the ps command which behaves differently or is missing on Windows.
  • Can cause errors or return empty results on Windows environments.
// ps-node: Unix-focused
// May fail or return nothing on Windows
ps.lookup({ command: 'nginx' }, (err, list) => {
  // Risk: 'ps' command might not exist on Windows
});

⚑ API Design: Promises vs Callbacks

pidusage supports both Callbacks and Promises.

  • You can use await for cleaner async code.
  • Flexible for older and newer codebases.
// pidusage: Promise support
const stats = await pidusage.stat(process.pid);
console.log(stats.cpu);

ps-list uses modern Promises by default.

  • Fits naturally into async/await workflows.
  • No need to wrap callbacks manually.
// ps-list: Promise-based
const processes = await psList();
const nodeProcesses = processes.filter(p => p.name === 'node');

ps-node relies on Callbacks.

  • Requires wrapping in a Promise for modern async/await usage.
  • Adds extra boilerplate to your code.
// ps-node: Callback-based
const util = require('util');
const lookup = util.promisify(ps.lookup);

// Must promisify manually to use await
const list = await lookup({ command: 'node' });

πŸ“Š Data Detail: Metrics vs Metadata

pidusage provides deep performance metrics.

  • Returns CPU percentage, memory usage, and elapsed time.
  • Essential for observability and alerting.
// pidusage: Detailed metrics
// { cpu: 12.5, memory: 45000000, ppid: 1234, ... }

ps-list provides broad process metadata.

  • Returns command name, PID, parent PID, and sometimes CPU/Mem.
  • Good for inventory and process discovery.
// ps-list: Process metadata
// { pid: 1234, name: 'node', cmd: 'node app.js', ... }

ps-node provides command-line argument details.

  • Focuses on the command and arguments used to start the process.
  • Useful for identifying specific instances of a program.
// ps-node: Command arguments
// { pid: 1234, command: 'node', arguments: ['app.js', '--prod'] }

πŸ› οΈ Maintenance and Future-Proofing

pidusage is actively maintained.

  • Regular updates fix OS-specific bugs.
  • Safe for long-term production use.

ps-list is highly active and trusted.

  • Maintained by a leading open-source contributor.
  • Widely adopted in the ecosystem.

ps-node has low maintenance activity.

  • Updates are infrequent.
  • Consider ps-list or node-pty for new projects requiring process management.

πŸ“Œ Summary Table

Featurepidusageps-listps-node
Primary GoalCPU/Mem StatsList All ProcessesLookup by Args
InputSpecific PIDNone (All)Query Object
OutputMetrics ObjectArray of ProcessesArray of Matches
PlatformWindows, Linux, macOSWindows, Linux, macOSLinux, macOS (Unix)
API StyleCallback / PromisePromiseCallback
MaintenanceActiveActiveLow

πŸ’‘ The Big Picture

pidusage is your go-to for performance monitoring.
Use it when you need to know how much resource a specific process is consuming. It is perfect for dashboards, health checks, and auto-scaling logic.

ps-list is the standard for process discovery.
Use it when you need to see what is running on the machine. It is ideal for security scanners, CLI tools, and system administration scripts that need to run everywhere.

ps-node is a legacy utility for Unix process management.
Use it only if you are maintaining older scripts that rely on its specific argument lookup features. For new projects, prefer ps-list for listing and native process.kill for management.

Final Thought: For modern Node.js development, ps-list and pidusage form a powerful combination β€” one tells you what is running, and the other tells you how hard it is working. Avoid ps-node unless you have a specific Unix-only requirement that the others do not meet.

How to Choose: pidusage vs ps-list vs ps-node

  • pidusage:

    Choose pidusage when you need precise CPU and memory metrics for a specific process, such as monitoring your own application or a child process. It is the best option for building health checks or performance dashboards that track resource consumption over time. Its cross-platform support ensures consistent data on Windows, Linux, and macOS without extra configuration.

  • ps-list:

    Choose ps-list if you need to list all running processes on the system in a modern, Promise-based workflow. It is ideal for security tools, system monitors, or scripts that need to identify processes by name across different operating systems. Its active maintenance and clean API make it the safest choice for new cross-platform projects.

  • ps-node:

    Choose ps-node only for legacy Unix-based scripts where you need to find processes by command arguments or kill them directly. It is not recommended for new cross-platform applications due to limited Windows support and lower maintenance activity. Use it if you are maintaining older infrastructure that already relies on its specific lookup features.

README for pidusage

pidusage

Lint MacOS Ubuntu Windows Alpine Code coverage npm version license

Cross-platform process cpu % and memory usage of a PID.

Synopsis

Ideas from https://github.com/arunoda/node-usage but with no C-bindings.

Please note that if you need to check a Node.JS script process cpu and memory usage, you can use process.cpuUsage and process.memoryUsage since node v6.1.0. This script remain useful when you have no control over the remote script, or if the process is not a Node.JS process.

Usage

var pidusage = require('pidusage')

pidusage(process.pid, function (err, stats) {
  console.log(stats)
  // => {
  //   cpu: 10.0,            // percentage (from 0 to 100*vcore)
  //   memory: 357306368,    // bytes
  //   ppid: 312,            // PPID
  //   pid: 727,             // PID
  //   ctime: 867000,        // ms user + system time
  //   elapsed: 6650000,     // ms since the start of the process
  //   timestamp: 864000000  // ms since epoch
  // }
  cb()
})

// It supports also multiple pids
pidusage([727, 1234], function (err, stats) {
  console.log(stats)
  // => {
  //   727: {
  //     cpu: 10.0,            // percentage (from 0 to 100*vcore)
  //     memory: 357306368,    // bytes
  //     ppid: 312,            // PPID
  //     pid: 727,             // PID
  //     ctime: 867000,        // ms user + system time
  //     elapsed: 6650000,     // ms since the start of the process
  //     timestamp: 864000000  // ms since epoch
  //   },
  //   1234: {
  //     cpu: 0.1,             // percentage (from 0 to 100*vcore)
  //     memory: 3846144,      // bytes
  //     ppid: 727,            // PPID
  //     pid: 1234,            // PID
  //     ctime: 0,             // ms user + system time
  //     elapsed: 20000,       // ms since the start of the process
  //     timestamp: 864000000  // ms since epoch
  //   }
  // }
})

// If no callback is given it returns a promise instead
const stats = await pidusage(process.pid)
console.log(stats)
// => {
//   cpu: 10.0,            // percentage (from 0 to 100*vcore)
//   memory: 357306368,    // bytes
//   ppid: 312,            // PPID
//   pid: 727,             // PID
//   ctime: 867000,        // ms user + system time
//   elapsed: 6650000,     // ms since the start of the process
//   timestamp: 864000000  // ms since epoch
// }

// Avoid using setInterval as they could overlap with asynchronous processing
function compute(cb) {
  pidusage(process.pid, function (err, stats) {
    console.log(stats)
    // => {
    //   cpu: 10.0,            // percentage (from 0 to 100*vcore)
    //   memory: 357306368,    // bytes
    //   ppid: 312,            // PPID
    //   pid: 727,             // PID
    //   ctime: 867000,        // ms user + system time
    //   elapsed: 6650000,     // ms since the start of the process
    //   timestamp: 864000000  // ms since epoch
    // }
    cb()
  })
}

function interval(time) {
  setTimeout(function() {
    compute(function() {
      interval(time)
    })
  }, time)
}

// Compute statistics every second:
interval(1000)

// Above example using async/await
const compute = async () => {
  const stats = await pidusage(process.pid)
  // do something
}

// Compute statistics every second:
const interval = async (time) => {
  setTimeout(async () => {
    await compute()
    interval(time)
  }, time)
}

interval(1000)

Compatibility

PropertyLinuxFreeBSDNetBSDSunOSmacOSWinAIXAlpine
cpuβœ…β“β“β“βœ…β„ΉοΈβ“βœ…
memoryβœ…β“β“β“βœ…βœ…β“βœ…
pidβœ…β“β“β“βœ…βœ…β“βœ…
ctimeβœ…β“β“β“βœ…βœ…β“βœ…
elapsedβœ…β“β“β“βœ…βœ…β“βœ…
timestampβœ…β“β“β“βœ…βœ…β“βœ…

βœ… = Working ℹ️ = Not Accurate ❓ = Should Work ❌ = Not Working

Please if your platform is not supported or if you have reported wrong readings file an issue.

By default, pidusage will use procfile parsing on most unix systems. If you want to use ps instead use the usePs option:

pidusage(pid, {usePs: true})

API

pidusage(pids, [options = {}], [callback]) β‡’ [Promise.<Object>]

Get pid informations.

Kind: global function Returns: Promise.<Object> - Only when the callback is not provided. Access: public

ParamTypeDescription
pidsNumber | Array.<Number> | String | Array.<String>A pid or a list of pids.
[options]objectOptions object. See the table below.
[callback]functionCalled when the statistics are ready. If not provided a promise is returned instead.

options

Setting the options programatically will override environment variables

ParamTypeEnvironment variableDefaultDescription
[usePs]booleanPIDUSAGE_USE_PSfalseWhen true uses ps instead of proc files to fetch process information
[maxage]numberPIDUSAGE_MAXAGE60000Max age of a process on history.

PIDUSAGE_SILENT=1 can be used to remove every console message triggered by pidusage.

pidusage.clear()

If needed this function can be used to delete all in-memory metrics and clear the event loop. This is not necessary before exiting as the interval we're registring does not hold up the event loop.

Related

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.