New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

node-command-line

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-command-line

Simple command line interface to execute command from node environment with promise

Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
416
-16.3%
Maintainers
1
Weekly downloads
 
Created
Source

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.

GitHub Info:

node-command-line GitHub Release GitHub license node-command-line license open issues for node-command-line on GitHub

##Method

methodargumentfunctionality
runcommandrun command synchronously/asynchronously based on using yield

##Examples

Inject the dependencies

var cmd     = require('node-command-line'),
    Promise = require('bluebird');

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.

Output in console like:

 Executed your command :)
 
 v6.2.1
 

Execute the single command with wait (using promise)

function runSingleCommandWithWait() {
  Promise.coroutine(function *() {
    yield 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:

 v6.2.1
 
 Executed your command :)
 

Execute the multiple command without wait

function runMultipleCommandWithoutWait() {
  Promise.coroutine(function *() {
    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 :)
 
 v6.2.1
 
 3.10.2
 

Execute the multiple command without wait

function runMultipleCommandWithWait() {
  Promise.coroutine(function *() {
    var commands = ["node --version","npm --version"];
    for(var i=0; i < commands.length; i++) {
      yield 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:

 
 v6.2.1
 
 3.10.2
 
 Executed your command :)
 

Execute the single command with wait and get response (using yield)

function runSingleCommandWithWait() {
  Promise.coroutine(function *() {
    var response = yield cmd.run('node --version');
    if(response.success) {
       // 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 :)');
  })();
}

Keywords

node.js

FAQs

Package last updated on 24 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts