shared-config

Configuration shared between browser and server.

Usage no npm install needed!

<script type="module">
  import sharedConfig from 'https://cdn.skypack.dev/shared-config';
</script>

README

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