Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bulyshko/config.json
nconf wrapper that simplifies work with environment specific configuration files
https://github.com/bulyshko/config.json
Last synced: 2 months ago
JSON representation
nconf wrapper that simplifies work with environment specific configuration files
- Host: GitHub
- URL: https://github.com/bulyshko/config.json
- Owner: bulyshko
- License: mit
- Archived: true
- Created: 2013-04-04T14:05:35.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2022-08-28T09:10:09.000Z (almost 2 years ago)
- Last Synced: 2024-02-24T12:41:51.512Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 15
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome - config.json - nconf wrapper that simplifies work with environment specific configuration files (JavaScript)
README
# config.json
[nconf][nconf] wrapper that simplifies work
with environment specific configuration files.**config.json** is easy to use; it:
- loads the default configuration file;
- loads environment specific configuration file and overrides defaults;and then:
- uses environment variables;
- and command-line arguments to override data from configuration files.**This package is no longer supported.**
## Installation
```
npm install config.json
```## Usage
The top-level of `config.json` is a function that loads configuration file with the given `filepath`.
### Create default configuration file
```
vi sample.json
``````json
{
"domain": "www.example.com",
"mongodb": {
"host": "localhost",
"port": 27017
}
}
```### Create environment specific configuration file
```
vi sample.development.json
``````json
{
"domain": "dev.example.com"
}
```**Note:** Environment specific configuration files should be in the same directory as the default one.
### Test config.json in action
```
vi sample.js
``````js
var config = require('config.json')('./sample.json');console.log("domain:", config.domain);
console.log("mongodb:\n",
"host:", config.mongodb.host, "\n",
"port:", config.mongodb.port);
```Run the above script:
```
NODE_ENV=development node ./sample.js --mongodb:host "dharma.mongohq.com" --mongodb:port 10065
```The output will be:
```
domain: dev.example.com
mongodb:
host: dharma.mongohq.com
port: 10065
```### Load configuration for the specific environment
Environment can be set by passing `env` argument:
```js
var developmentConfig = require('config.json')('./sample.json', 'development');
var productionConfig = require('config.json')('./sample.json', 'production');
```### One more thing...
`filepath` can be empty if your configuration file is in the current working directory of the process and is called **config.json**.
## License
Released under the [MIT license][license].
[nconf]:https://github.com/flatiron/nconf
[license]:https://raw.github.com/bulyshko/config.json/master/LICENSE
[build]:https://travis-ci.org/bulyshko/config.json.svg?branch=master
[travis]:https://travis-ci.org/bulyshko/config.json
[dependency]:https://david-dm.org/bulyshko/config.json.svg?theme=shields.io
[david]:https://david-dm.org/bulyshko/config.json