Node.js Process Lookup Utility

0.1.6 · abandoned · verified Sun Apr 19

ps-node is a Node.js module designed for looking up and managing running processes across different operating systems. It leverages native system commands like `ps` on Linux/macOS and `wmic` on Windows to retrieve detailed process information, including PID, command, and arguments. The package, currently at version 0.1.6, was last published nine years ago. Its primary functionality includes searching for processes by PID or filtering by command and arguments using regular expressions. Additionally, it offers a `kill` function to terminate processes, supporting optional signals and timeouts. Due to its age, it does not support modern Node.js features like ECMAScript Modules (ESM) and is likely incompatible with recent Node.js versions or major operating system updates. There is no ongoing release cadence, and it is largely superseded by more actively maintained alternatives.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `ps-node` to find running Node.js processes with specific debug arguments and then, as an example, attempts to terminate the first matching process.

const ps = require('ps-node');

// Look up processes matching a command and arguments
ps.lookup({
    command: 'node',
    arguments: '--debug'
}, function(err, resultList) {
    if (err) {
        console.error('Error looking up processes:', err);
        process.exit(1);
    }

    if (resultList.length === 0) {
        console.log('No matching processes found.');
        return;
    }

    console.log('Found matching processes:');
    resultList.forEach(function(process) {
        console.log('  PID: %s, COMMAND: %s, ARGUMENTS: %s', process.pid, process.command, process.arguments);
    });

    // Example: Kill the first found process after 5 seconds (for demonstration)
    if (resultList[0]) {
        const pidToKill = resultList[0].pid;
        console.log(`
Attempting to kill process ${pidToKill} in 5 seconds...`);
        setTimeout(() => {
            ps.kill(pidToKill, { signal: 'SIGTERM', timeout: 10 }, function(killErr) {
                if (killErr) {
                    console.error(`Error killing process ${pidToKill}:`, killErr);
                } else {
                    console.log(`Process ${pidToKill} has been killed!`);
                }
            });
        }, 5000);
    }
});

view raw JSON →