node-run-cmd is a Node.js package designed to execute console or terminal commands programmatically. It supports both single and multiple commands, with options for sequential or parallel execution. The current stable version is 1.0.1, marking its initial public release. It offers robust control over command execution, including setting working directories, environment variables, detached mode, and callbacks for data, errors, and completion. It returns promises for asynchronous handling and also supports a callback style. Key differentiators include its detailed options object for fine-grained control over child processes and the ability to define different working directories for individual commands within an array. The package explicitly cautions against its use for cross-platform applications or when `node-fs-extra` can accomplish filesystem-related tasks more effectively, positioning itself as a solution for specific, platform-dependent command execution needs.
npm install node-run-cmdVerified import paths — ran on the pinned version, not inferred.
Demonstrates installing the package, running multiple shell commands with options, and handling promise-based success and error states, including a basic cleanup.
If cross-platform compatibility is a requirement, consider using platform-agnostic Node.js APIs (e.g., `fs` module) or libraries like `node-fs-extra` for file system operations, or abstracting commands based on `process.platform`.
For common file system operations (e.g., creating/deleting directories or files), prefer using `node-fs-extra` to leverage its native Node.js APIs and cross-platform reliability.
Be meticulous about command string construction, especially with paths and arguments containing spaces or special characters. Use proper escaping (e.g., backticks, double quotes) according to the target shell. For robustness, consider passing command arguments as an array if the underlying `child_process` API allows.
Verify that the command (`<command>`) is installed and available in the system's PATH. If not, provide the full absolute path to the executable or ensure it's installed globally or within `node_modules/.bin` if applicable.
Inspect the `stderr` output (available via the `onError` callback or within the error object of the promise rejection) to diagnose the specific issue with the command. This often relates to incorrect arguments, file permissions, or environmental issues for the command itself.
Ensure that `const nrc = require('node-run-cmd');` is correctly placed and executed before attempting to call `nrc.run(...)`. Verify the package is installed in `node_modules`.No dependency data recorded yet.