Configuration shared between browser and server.
npm install shared-configConfiguration shared by browser and server.
Using [npm][0]:
``sh`
npm install shared-config
Using [component][1]:
`sh`
component install shared-config
Configuration files are loaded from config/ in your application directory,process.env.NODE_CONFIG_PATH
or from if set.
Configuration files can be json, yaml, or modules. config/default.ext isconfig/
loaded first, extended with if it exists,config/local.ext
and finally extended with if it exists.
Require the configuration on your server and then send to the client by setting
the config cookie.
config/default.yaml:
`yaml`
api:
url: 'https://api.example.com'
Server:
`javascript
var config = require('shared-config');
app
.use(express.static('./public'))
.get('/', function(req, res, next) {
res.cookie('config', config);
res.render('template', locals);
});
`
Browser:
`javascript
var config = require('shared-config');
console.log(config.api);
// => { url: 'https://api.example.com' }
``
[0]: https://npmjs.org/
[1]: https://github.com/component/component/