diff --git a/lib/run.js b/lib/run.js index d41102d..4d97bfc 100644 --- a/lib/run.js +++ b/lib/run.js @@ -13,8 +13,8 @@ var remap = { * * @param main the module to run */ -var run = module.exports = function(main) { - var options = {}, argv = []; +var run = module.exports = function(main, options) { + options = options || {}, argv = []; process.argv.forEach(function(arg) { if (!arg.indexOf('-')) { options[arg.substr(1)] = true; @@ -73,7 +73,11 @@ var run = module.exports = function(main) { if (module.app) { var httpserver = require('./httpserver'); if (!httpserver.started) { - httpserver.main(module.app, argv[2], {cluster:argv[3]}); + httpserver.main(module.app, + (options.port || argv[2]), + { + cluster: (options.cluster || argv[3]) + }); } } } @@ -104,7 +108,8 @@ var run = module.exports = function(main) { } }; + if (require.main === module) { process.argv.shift(); // remove node, which is first arg run(); -} \ No newline at end of file +} diff --git a/package.json b/package.json index 31ab3fc..1d012b2 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,9 @@ }, "homepage":"http://github.com/olegp/common-node/", "main":"./lib/all.js", + "scripts": { + "test": "node test/all.js" + }, "bin":{ "common-node":"./bin/common-node" }, @@ -44,4 +47,4 @@ "type":"MIT" } ] -} \ No newline at end of file +}