Installations
npm install node-run-cmd
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
5.1.0
NPM Version
3.3.12
Score
76.2
Supply Chain
100
Quality
75.1
Maintenance
100
Vulnerability
100
License
Contributors
Unable to fetch Contributors
Languages
JavaScript (99.69%)
Shell (0.31%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
c-h-
Download Statistics
Total Downloads
1,957,788
Last Day
504
Last Week
1,615
Last Month
9,274
Last Year
149,974
GitHub Statistics
15 Stars
10 Commits
6 Forks
2 Watching
1 Branches
1 Contributors
Bundle Size
1.77 kB
Minified
870.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.0.1
Package Id
node-run-cmd@1.0.1
Size
6.07 kB
NPM Version
3.3.12
Node Version
5.1.0
Total Downloads
Cumulative downloads
Total Downloads
1,957,788
Last day
7.2%
504
Compared to previous day
Last week
-26.1%
1,615
Compared to previous week
Last month
8.3%
9,274
Compared to previous month
Last year
-42.6%
149,974
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
5
node-run-cmd
Node.js commandline/terminal interface.
Easily run simple or sophisticated console/terminal command(s) from Node. Supports sequential and parallel execution. Returns a promise that resolves to an array of exit codes for each command run.
With node-run-cmd you can execute a single command or an array of commands quite simply.
If you want, set in-depth options for commands being run, including callbacks for data, errors, and completion. Also set working directory, environment variables, run execution process in detached mode, set the uid and gid for the execution process(es), and set the shell to run the command in.
The source that this package is based on has been in production since February, 2016. Note that the examples here are for illustrative purposes only; most of the time there is no real need to run commands from Node, and they should be avoided if there are cross-platform requirements. This package aims to help when there isn't an agreeable alternative.
If most of your commands are filesystem related, I would instead look to node-fs-extra to accomplish what the commands would have.
NPM:
GitHub:
Licensed via MIT License.
Quick Start
The quickest way to get started is to run a single, simple command, then increase complexity as needed.
Install the package:
1$ npm install --save node-run-cmd
Use the package:
1var nrc = require('node-run-cmd'); 2nrc.run('mkdir foo');
Examples
These examples get increasingly complex to demonstrate the robustness of the package. Not all options are demonstrated; see the Options Object section for all possible options.
Simple command
1nrc.run('mkdir foo');
Aysnchronous usage
Promise style
1nrc.run('mkdir foo').then(function(exitCodes) { 2 doSomethingElse(); 3}, function(err) { 4 console.log('Command failed to run with error: ', err); 5});
Callback style
1var callback = function (exitCodes) { 2 doSomethingElse(); 3}; 4nrc.run('mkdir foo', { onDone: callback } );
Use output (stdout) from command
1var dataCallback = function(data) { 2 useData(data); 3}; 4nrc.run('ls', { onData: dataCallback });
Use error output (stderr) from command
1var errorCallback = function(data) { 2 useErrorData(data); 3}; 4nrc.run('ls ~/does/not/exist', { onError: dataCallback });
Use exit code from command
1var doneCallback = function(code) { 2 useCode(code); 3}; 4nrc.run('ls foo', { onDone: doneCallback });
OR
1nrc.run('ls foo').then(function(codes){ useCode(codes[0]); });
Run multiple commands
1nrc.run([ 'mkdir foo', 'touch foo/bar.txt' ]);
Set working directory for commands
1var commands = [ 2 'mkdir foo', 3 'touch foo/bar.txt' 4]; 5var options = { cwd: 'path/to/my/dir' }; 6nrc.run(commands, options);
Set different working directory for each command
1var commands = [ 2 { command: 'mkdir foo', cwd: 'dir1' }, 3 { command: 'mkdir foo', cwd: 'dir2' } 4]; 5nrc.run(commands);
Set different working directory one command and default working directory for the others
1var commands = [ 2 'mkdir foo', 3 { command: 'mkdir foo', cwd: 'different/dir' }, 4 'mkdir bar' 5]; 6var options = { cwd: 'default/dir' }; 7nrc.run(commands, options);
Run commands in parallel
1var commands = [ 2 './runCompute1.sh', 3 './runCompute2.sh', 4 './runCompute3.sh', 5]; 6var options = { mode: 'parallel' }; 7nrc.run(commands, options);
NRC Methods
Run
Usage:
1var promise = nrc.run(commands, globalOptions);
Returns:
A promise that resolves to an array of exit codes for commands run.
Arguments:
commands
can be specified in any one of the below formats
name | type | required | description | example |
---|---|---|---|---|
commands | string | yes | The command to run | 'ls' |
commands | array(string) | yes | An array of string commands to run | ['ls', 'mkdir foo'] |
commands | array(object) | yes | An array of objects describing commands to run. See section Options Object for allowed properties. | [{ command: 'ls' }, { command: 'mkdir foo' }] |
commands | array(object or string) | yes | A mixed array of objects describing commands and string commands to run. See section Options Object for allowed properties. | [{ command: 'ls' }, 'mkdir foo'] |
globalOptions | object | no | The global options to set for each command being run. Overridden by command's options. | { cwd: 'foo', verbose: true, logger: gutil.log } |
Options Object
Options available for the commands
or globalOptions
argument:
property | type | required | default | description |
---|---|---|---|---|
command | string | yes | - | the command to run |
cwd | string | no | process.cwd() | the directory to run the command in |
onData | function(data) | no | null | where to send output from stdout. Called each time stdout is written. |
onError | function(data) | no | null | where to send output from stderr. Called each time stderr is written. |
onDone | function(code) | no | null | where to send the exit code of the command. Called once. |
verbose | boolean | no | false | show verbose output |
logger | function(data) | no | console.log | what function to use to log when verbose is set to true |
env | object | no | null | Environment key-value pairs |
stdio | string or array | no | null | Child's stdio configuration |
detached | boolean | no | null | Prepare child to run independently of its parent process. Specific behavior depends on the platform. |
uid | number | no | null | Sets the user identity of the process. |
gid | number | no | null | Sets the group identity of the process. |
shell | boolean or string | no | null | If true, runs command inside of a shell. Uses '/bin/sh' on UNIX, and 'cmd.exe' on Windows. A different shell can be specified as a string. The shell should understand the -c switch on UNIX, or /s /c on Windows. Defaults to false (no shell). |
Global-Only Commands
These options can only be set in the globalOptions
argument.
property | type | required | default | description |
---|---|---|---|---|
mode | string | no | 'sequential' | Whether to run commands in series (sequentially) or in parallel. |
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/10 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to node-run-cmd
node-cmd
Simple commandline/terminal/shell interface to allow you to run cli or bash style commands as if you were in the terminal.
snorun
Run & interact with shell command like in node without pain.
node-cmd-promise
Node interface to allow you to run bash commands asynchronously with Promises
msnode-cmd
Simple commandline/terminal interface to allow you to run cli or bash style commands as if you were in the terminal.