Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #146 from rowanhill/configurable-config-json

Allow config.json location to be configured by argument to app.js
  • Loading branch information...
commit 0377b7824292536c69c97e833fd7da1a5afced17 2 parents 1c76d40 + 2c1bac1
@mtougeron mtougeron authored
Showing with 28 additions and 3 deletions.
  1. +9 −0 README.md
  2. +17 −2 app.js
  3. +2 −1  package.json
View
9 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)
View
19 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);
}
View
3  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",
Please sign in to comment.
Something went wrong with that request. Please try again.