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.
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.
pidusage focuses on a single Process ID.
// 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.
// 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.
// 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}`);
});
});
pidusage works consistently across major OSs.
// 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.
// 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.
ps command which behaves differently or is missing on Windows.// 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
});
pidusage supports both Callbacks and Promises.
await for cleaner async code.// pidusage: Promise support
const stats = await pidusage.stat(process.pid);
console.log(stats.cpu);
ps-list uses modern Promises by default.
async/await workflows.// ps-list: Promise-based
const processes = await psList();
const nodeProcesses = processes.filter(p => p.name === 'node');
ps-node relies on Callbacks.
// 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' });
pidusage provides deep performance metrics.
// pidusage: Detailed metrics
// { cpu: 12.5, memory: 45000000, ppid: 1234, ... }
ps-list provides broad process metadata.
// ps-list: Process metadata
// { pid: 1234, name: 'node', cmd: 'node app.js', ... }
ps-node provides command-line argument details.
// ps-node: Command arguments
// { pid: 1234, command: 'node', arguments: ['app.js', '--prod'] }
pidusage is actively maintained.
ps-list is highly active and trusted.
ps-node has low maintenance activity.
ps-list or node-pty for new projects requiring process management.| Feature | pidusage | ps-list | ps-node |
|---|---|---|---|
| Primary Goal | CPU/Mem Stats | List All Processes | Lookup by Args |
| Input | Specific PID | None (All) | Query Object |
| Output | Metrics Object | Array of Processes | Array of Matches |
| Platform | Windows, Linux, macOS | Windows, Linux, macOS | Linux, macOS (Unix) |
| API Style | Callback / Promise | Promise | Callback |
| Maintenance | Active | Active | Low |
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.
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.
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.
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.
Cross-platform process cpu % and memory usage of a PID.
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.
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)
| Property | Linux | FreeBSD | NetBSD | SunOS | macOS | Win | AIX | Alpine |
|---|---|---|---|---|---|---|---|---|
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})
[Promise.<Object>]Get pid informations.
Kind: global function
Returns: Promise.<Object> - Only when the callback is not provided.
Access: public
| Param | Type | Description |
|---|---|---|
| pids | Number | Array.<Number> | String | Array.<String> | A pid or a list of pids. |
| [options] | object | Options object. See the table below. |
| [callback] | function | Called when the statistics are ready. If not provided a promise is returned instead. |
Setting the options programatically will override environment variables
| Param | Type | Environment variable | Default | Description |
|---|---|---|---|---|
| [usePs] | boolean | PIDUSAGE_USE_PS | false | When true uses ps instead of proc files to fetch process information |
| [maxage] | number | PIDUSAGE_MAXAGE | 60000 | Max age of a process on history. |
PIDUSAGE_SILENT=1 can be used to remove every console message triggered by pidusage.
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.
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details.