c0nfig

1.0.6 • Public • Published

c0nfig

npm version Dependency Status

Require local environment based configs as if they are in node_modules.

Install

npm install c0nfig --save

Usage

Create configs for every app environment just putting the env name as prefix of the file name:

app-folder/config:~$ ls -a
 
production.config.js
development.config.js
# etc. 

Export some configuration data for every environment like:

// config/development.config.js
module.exports = {
  title: 'BLITZKRIEG BOP (STAGING)',
  apiUrl: 'https://staging.example.org/api'
};
// config/production.config.js
module.exports = {
  title: 'BLITZKRIEG BOP (PRODUCTION)',
  apiUrl: 'https://example.org/api'
};

Start your app with proper NODE_ENV (if not provided it will grab development.config.js by default), then require/import c0nfig in your source code and use the data:

// src/app.js
import config from 'c0nfig';
import request from 'superagent';
 
request.get(config.apiUrl).then(res => { ... });
// src/app.js
const config = require('c0nfig');
const request = require('superagent');
 
request.get(config.apiUrl).then(res => { ... });

Template tags

You are able to use template tags like $(configProperty.childProperty) to point to specific properties of config:

module.exports = {
  title: 'BLITZKRIEG BOP!',
  http: {
    port: process.env.PORT || 8080,
    url: process.env.URL || 'http://0.0.0.0:$(http.port)'
  }
};

MIT Licensed

Package Sidebar

Install

npm i c0nfig

Weekly Downloads

37

Version

1.0.6

License

MIT

Unpacked Size

4.84 kB

Total Files

3

Last publish

Collaborators

  • dmitri