Skip to content

Instantly share code, notes, and snippets.

@lkptrzk
Created October 23, 2015 16:46
Show Gist options
  • Save lkptrzk/1ae5ede0962ad5b0c1e1 to your computer and use it in GitHub Desktop.
Save lkptrzk/1ae5ede0962ad5b0c1e1 to your computer and use it in GitHub Desktop.
nodejs script boilerplate
var Async = require('async');
exports.script = function () {
var options = internals.parseOptions();
var context = {
options: options,
state: {},
};
var tasks = internals.tasks.map(function (task) {
return task.bind(context);
});
Async.series(tasks, function (err, results) {
if (err) {
throw err;
}
process.exit(0);
});
};
var internals = exports._internals = {
tasks: [],
};
internals.parseOptions = function () {
var options = {};
return options;
};
internals.tasks[0] = function (callback) {
var context = this;
console.log('task 0');
return callback(null);
};
internals.tasks[1] = function (callback) {
var context = this;
console.log('task 1');
return callback(null);
};
if (require.main === module) {
exports.script();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment