Skip to content

Instantly share code, notes, and snippets.

@eins78
Last active December 20, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eins78/6125347 to your computer and use it in GitHub Desktop.
Save eins78/6125347 to your computer and use it in GitHub Desktop.
flatiron-nconf-wtf
/node_modules/

a strange bug

{
"foo": "WTF"
}
var flatiron = require('flatiron'),
path = require('path'),
app = flatiron.app;
app.config.argv();
app.config.env();
app.config.file({ file: 'config.json' });
console.log('foo: ' + app.config.get('foo'));
app.init();
console.log('foo: ' + app.config.get('foo'));
var flatiron = require('flatiron'),
path = require('path'),
app = flatiron.app;
app.config.argv();
app.config.env();
app.config.file('file', { file: 'config.json' });
app.use(flatiron.plugins.cli);
// we run this with `node file.js --foo=bar`
console.log('foo: ' + app.config.get('foo'));
// now, `foo` is equal to config from argv
// the `init` changes the `app.config` ???
app.init();
console.log('foo: ' + app.config.get('foo'));
// now, `foo` is equal to config from `file` :/
var fs = require('fs'),
nconf = require('nconf');
//
// Setup nconf to use (in-order):
// 1. Command-line arguments
// 2. Environment variables
// 3. A file located at 'path/to/config.json'
//
nconf.argv()
.env()
.file({ file: 'config.json' });
console.log('foo: ' + nconf.get('foo'));
console.log('foo: ' + nconf.get('foo'));
{
"name": "nconf-test",
"version": "0.0.0",
"description": "",
"main": "app.js",
"dependencies": {
"nconf": "~0.6.7",
"union": "0.3.5",
"flatiron": "0.3.8",
"vows": "~0.7.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD"
}
var vows = require('vows'),
assert = require('assert'),
exec = require('child_process').exec;
var expected = "foo: bar";
function run (testfile, callback) {
var cmd = 'node ' + testfile + '.js --foo=bar';
exec(cmd, function (err, stdout, stderr) {
callback(err || null, stdout);
});
}
var suite = vows.describe('nconf + flatiron = WTF').export(module);
suite.addBatch({
'Run just-nconf --foo=bar' : {
topic: function() {
run('just-nconf', this.callback);
},
'foo=bar': function (topic) {
assert.equal(topic.split('\n')[0], expected);
}
},
'Run flatiron-app --foo=bar' : {
topic: function() {
run('flatiron-app', this.callback);
},
'foo=bar': function (topic) {
assert.equal(topic.split('\n')[0], expected);
},
'foo=bar after init()': function (topic) {
assert.equal(topic.split('\n')[1], expected);
}
},
'Run flatiron-cli --foo=bar' : {
topic: function() {
run('flatiron-cli', this.callback);
},
'foo=bar': function (topic) {
assert.equal(topic.split('\n')[0], expected);
},
'foo=bar after init()': function (topic) {
assert.equal(topic.split('\n')[1], expected);
}
}
});
// suite.run();
#!/bin/sh
echo "just-nconf"
node just-nconf.js --foo=bar
echo "flatiron-app"
node flatiron-app.js --foo=bar
echo "flatiron-cli.js"
node flatiron-cli.js --foo=bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment