Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

exec-series

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

exec-series

Run commands in order

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

exec-series

NPM version Build Status Build status Coverage Status Dependency Status devDependency Status

A Node module to run commands in order

const execSeries = require('exec-series');

execSeries(['echo "foo"', 'echo "bar"'], (err, stdouts, stderrs) => {
  if (err) {
    throw err;
  }

  console.log(stdouts); // yields: ['foo\n', 'bar\n']
  console.log(stderrs); // yields: ['', '']
});

On Linux, you can do almost the same thing with && operator like below:

const {exec} = require('child_process');

exec('echo "foo" && echo "bar"', (err, stdout, stderr) => {
  //...
});

However, some environments, such as Windows PowerShell, don't support && operator. This module helps you to create a cross-platform Node program.

Installation

Use npm.

npm install exec-series

API

const execSeries = require('exec-series');

execSeries(commands [, options, callback])

commands: Array of String (the commands to run)
options: Object (child_process.exec options with maxBuffer defaulting to 10 MB)
callback: Function

It sequentially runs the commands using child_process.exec. If the first command has finished successfully, the second command will run, and so on.

After the last command has finished, it runs the callback function.

When one of the commands fails, it immediately calls the callback function and the rest of the commands won't be run.

callback(error, stdoutArray, stderrArray)

error: Error if one of the commands fails, otherwise undefined
stdoutArray: Array of String (stdout of the commands)
stderrArray: Array of String (stderr of the commands)

execSeries([
  'mkdir foo',
  'echo bar',
  'exit 200',
  'mkdir baz'
], (err, stdouts, stderrs) => {
  err.code; //=> 200
  stdouts; //=> ['', 'bar\n', '']
  stderrs; //=> ['', '', '']
  
  fs.statSync('foo').isDirectory; //=> true
  fs.statSync('baz'); // throw an error
});

Callback function is optional.

execSeries(['mkdir foo', 'mkdir bar']);

setTimeout(() => {
  fs.statSync('foo').isDirectory(); //=> true
  fs.statSync('bar').isDirectory(); //=> true
}, 1000);

License

Copyright (c) 2014 - 2016 Shinnosuke Watanabe

Licensed under the MIT License.

Keywords

FAQs

Package last updated on 11 Jul 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc