diff --git a/README.md b/README.md index 31ff7561..9fb560d1 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,15 @@ npm start (*nix, Mac OSX) npm run-script startwin (Windows) ``` +**Start I/O Docs with a custom config file**: + +``` +./node_modules/.bin/supervisor -e 'js|json' -- app --config-file ../config.json (*nix, Mac OSX) +supervisor -e 'js' -- app --config-file ../config.json (Windows) +``` + +Ideally, the `--config-file` arg would be possible to use with `npm start`, but until +[npm issue #3494](https://github.com/isaacs/npm/issues/3494) is resolved, this is not supported. **Point your browser** to: [localhost:3000](http://localhost:3000) diff --git a/app.js b/app.js index c8f06403..b7857b44 100755 --- a/app.js +++ b/app.js @@ -38,11 +38,26 @@ var express = require('express'), redis = require('redis'), RedisStore = require('connect-redis')(express); +// Parse arguments +var optimist = require('optimist') + .usage('Usage: $0 --config-file [file]') + .alias('c', 'config-file') + .alias('h', 'help') + .describe('c', 'Specify the config file location') + .default('c', './config.json'); +var argv = optimist.argv; + +if (argv.help) { + optimist.showHelp(); + process.exit(0); +} + // Configuration +var configFilePath = path.resolve(argv['config-file']); try { - var config = require('./config.json'); + var config = require(configFilePath); } catch(e) { - console.error("File config.json not found or is invalid. Try: `cp config.json.sample config.json`"); + console.error("File " + configFilePath + " not found or is invalid. Try: `cp config.json.sample config.json`"); process.exit(1); } diff --git a/package.json b/package.json index d549df0e..7f59c404 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "oauth": "0.9.10", "redis": "0.8.3", "querystring": "0.1.0", - "supervisor": ">= 0.5.x" + "supervisor": ">= 0.5.x", + "optimist": ">= 0.6.0" }, "devDependencies": {}, "main": "index",