shared-config

v0.3.2
Configuration shared between browser and server.
config browser client shared

shared-config

Configuration shared by browser and server.

Installation

Using npm:

npm install shared-config

Using component:

component install shared-config

Usage

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' }

MIT Licensed

npm i shared-config

Metadata

  • MIT
  • Whatever
  • Unknown
  • released 4/14/2014

Downloads

Maintainers