node package manager


 ____  ___,   __   _, ____,   ____,   ____, ___,
(-(__`(-|_)  (-|  |  (-|  |  (-|  |  (-|_, (-|_)
 ____) _| \_,  |__|_, _|  |_, _|  |_, _|__, _| \_,
(     (              (       (       (     (

Latest Stable Version NPM Downloads

Script Runner (srunner)

Break down large scripts into manageable steps


First create some script steps in some folder


module.exports = (state, options, cb) {
    // TODO: setup environment 


module.exports = (state, options, cb) {
    // TODO: start app servers 


module.exports = (state, options, cb) {
    // TODO: do something 


module.exports = (state, options, cb) {
    // TODO: kill servers 

Then write the main script


    var Runner = require('srunner').Runner
      , runner = new Runner();
        .init({ dir: './scripts', onError: 'killServers' })
        .startServers({ port: 9000 })

For more examples check out gcpk or scripts or mogen

sub-scripts method signature

The sub-scripts (steps) are expected to provide a single export method with the following signatures (any of these is allowed):

module.exports = function (state, options, cb)
module.exports = function (options, cb)
module.exports = function (cb)


  • state: is an object that is local to the runner object and it's passed to every step
  • options: is used to pass any parameter from the main script (see the startServers method above)
  • cb: is a callback method that must be called (potentially with an error). If called with an error all the steps following this one will be skipped and an error handler will be invoked if specified.


var Runner = require('srunner').Runner
  , runner = new Runner();


This method must be called first. It reads the scripts directory and creates methods on the runner based on the scripts found in the specified directory. Each file should be named with underscores and its corresponding method will be camel cased (e.g. do_stuff.js -> doStuff()).

where options is an object that can contain the following

  • dir: the scripts directory (this can be a string or an array)
  • onError: the name of the error handler that will be called in case of error
  • quiet: set to true to avoid printing the step name before each step executes
  • state: an object to set as the initial state


Will run the script. All methods will be run async and in the order called. On error (either unhandled or not) the specified error handler will be called, if any. This function can be passed a callback for further processing.

$ npm install srunner