Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow config.json location to be configured by argument to app.js #146

Merged
merged 1 commit into from Mar 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -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)

Expand Down
19 changes: 17 additions & 2 deletions app.js
Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -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",
Expand Down