0.3.2 • Published 12 years ago
shared-config v0.3.2
shared-config
Configuration shared by browser and server.
Installation
Using npm:
npm install shared-configUsing component:
component install shared-configUsage
Configuration files are loaded from config/ in your application directory,
or from process.env.NODE_CONFIG_PATH if set.
Configuration files can be json, yaml, or modules. config/default.ext is
loaded first, extended with config/<process.env.NODE_ENV>.ext if it exists,
and finally extended with config/local.ext if it exists.
Require the configuration on your server and then send to the client by setting
the config cookie.
config/default.yaml:
api:
url: 'https://api.example.com'Server:
var config = require('shared-config');
app
.use(express.static('./public'))
.get('/', function(req, res, next) {
res.cookie('config', config);
res.render('template', locals);
});Browser:
var config = require('shared-config');
console.log(config.api);
// => { url: 'https://api.example.com' }