Installations
npm install node-command-line
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
16.15.1
NPM Version
9.8.1
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
shaishab
Download Statistics
Total Downloads
312,768
Last Day
31
Last Week
532
Last Month
2,497
Last Year
30,421
GitHub Statistics
7 Stars
24 Commits
3 Watching
2 Branches
1 Contributors
Bundle Size
545.00 B
Minified
322.00 B
Minified + Gzipped
Package Meta Information
Latest Version
2.0.2
Package Id
node-command-line@2.0.2
Unpacked Size
9.77 kB
Size
2.83 kB
File Count
5
NPM Version
9.8.1
Node Version
16.15.1
Publised On
10 Aug 2023
Total Downloads
Cumulative downloads
Total Downloads
312,768
Last day
-32.6%
31
Compared to previous day
Last week
10.6%
532
Compared to previous week
Last month
29.6%
2,497
Compared to previous month
Last year
11.3%
30,421
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No dependencies detected.
node-command-line
Simple node.js commandline or terminal interface to execute cli commands from node environment with/without promise
using node-command-line you can run commands synchronously/asynchronously and get the output as a promise.
npm info :
GitHub Info:
Install the package
$ npm install --save node-command-line
Method
method | argument | functionality |
---|---|---|
run | command, true/false | run command synchronously/asynchronously based on using await and pass second parameter true or false to print from library or not. Default vaue is true. |
**Note:
I've added a basic sanitization step that removes characters commonly associated with shell command injection attacks. This helps prevent unwanted characters from being executed within the shell command.
Examples
Inject the dependencies
var cmd = require('node-command-line')
Ex1: Execute the single command without wait
function runSingleCommandWithoutWait() {
cmd.run('node --version');
console.log('Executed your command :)');
}
In this example run the command node --version
that will show the node version and also print Executed your command :)
.
node version may shown after print Executed your command :)
because of second command do not wait for executing the first command.
I've added a basic sanitization step that removes characters commonly associated with shell command injection attacks. This helps prevent unwanted characters from being executed within the shell command.
Output in console like:
Executed your command :)
v16.15.1
Ex2: Execute command and pass second parameter true/false to print from library or not
function runSingleCommandWithoutWait() {
cmd.run('node --version', false); // Will not print output from library
console.log('Executed your command :)');
}
In this example run the command node --version
that will not sow the node version but print Executed your command :)
.
node version won't show after print Executed your command :)
because the second parameter passed false.
Output in console like:
Executed your command :)
Ex3: Execute the single command with wait (using promise)
async function runSingleCommandWithWait() {
await cmd.run('node --version');
console.log('Executed your command :)');
}
In this example run the command node --version
that will show the node version and also print Executed your command :)
.
node version will show before print Executed your command :)
because of second command will execute after executing the first command.
Output in console like:
v16.15.1
Executed your command :)
Ex4: Execute the multiple command without wait
async function runMultipleCommandWithoutWait() {
var commands = ["node --version", "npm --version"];
for (var i = 0; i < commands.length; i++) {
cmd.run(commands[i]);
}
console.log('Executed your command :)');
}
In this example run the command node --version
and npm --version
that will show the node version and npm version also print Executed your command :)
.
node and npm version may shown after print Executed your command :)
because of `console.log`` do not wait for executing the first two command.
Output in console like:
Executed your command :)
v16.15.1
9.8.1
Ex5: Execute the multiple command without wait
async function runMultipleCommandWithWait() {
var commands = ["node --version", "npm --version"];
for (var i = 0; i < commands.length; i++) {
await cmd.run(commands[i]);
}
console.log('Executed your command :)');
}
In this example run the command node --version
and npm --version
that will show the node version and npm version also print Executed your command :)
.
node and npm version will show before print Executed your command :)
because of `console.log`` will be waiting for executing the first two command.
Output in console like:
v16.15.1
9.8.1
Executed your command :)
Ex6: Execute the single command with async wait and get response
async function runSingleCommandWithWaitAndGetResponse() {
let response = await cmd.run('node --version');
if(response.success) {
console.log('Response received===', response.message);
// do something
// if success get stdout info in message. like response.message
} else {
// do something
// if not success get error message and stdErr info as error and stdErr.
//like response.error and response.stdErr
}
console.log('Executed your command :)');
}
Output in console like:
Executed your command :)
![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/20 approved changesets -- score normalized to 0
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'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 7 are checked with a SAST tool
Score
3
/10
Last Scanned on 2025-01-27
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-command-line
inquirer
A collection of common interactive command line user interfaces.
cli-table3
Pretty unicode tables for the command line. Based on the original cli-table.
enquirer
Stylish, intuitive and user-friendly prompt system. Fast and lightweight enough for small projects, powerful and extensible enough for the most advanced use cases.
commander
the complete solution for node.js command-line programs