Skip to content

Commit

Permalink
implement the basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
eliOcs committed Mar 21, 2012
1 parent 0325ab3 commit e741c57
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -1,3 +1,7 @@
# NPM dependencies
node_modules
*.log
# VIM backup files
.*.swp
.*.swo
*~
50 changes: 46 additions & 4 deletions README.md
@@ -1,12 +1,13 @@
# ENVy

Handle your environment properties from a simple .json file.
Handle your project environment properties from a simple .json file.

## Installation

To install simply use the node package manager (NPM):

```
[sudo] npm install envy
[sudo] npm install envy
```

## Motivation
Expand All @@ -17,12 +18,53 @@ to handle many environments.

## Usage

### File format

The file defines what is your default environment from which all other
environments will inherit their properties.

In the following example the ```"development"``` environment will be selected
by default. _Selecting an environment in your configuration file will also make
its properties to be inherited in the other environments._
Continuing with the example, the ```"production"``` environment will also be
configured to use the port ```3000```, but its database url will be
```"mongodb://localhost/prod-app"``` instead of
```"mongodb://localhost/dev-app"```.

```json
{
"environment": "development",

"development": {
"port": 3000,
"database": {
"url": "mongodb://localhost/dev-app"
}
},

"production": {
"database": {
"url": "mongodb://localhost/prod-app"
}
}
}
```

### Using it in your program

When you ```require``` the envy module it will try to load the default configuration file: ```./config.json```.

``` js
var envy = require('envy');
var envy = require('envy');

envy.load('config.json');
envy.config.your.properties;
```

If you want to select an environment you will need to set the ```NODE_ENV```
environment variable:

```NODE_ENV=production node your-app.js```

## Future features

We plan on extending the current features and include:
Expand Down
22 changes: 22 additions & 0 deletions envy.js
@@ -0,0 +1,22 @@
// envy.js

var envy = module.exports;

// Load the .json file containing the
envy.load = function(filename) {

var config = require(filename);

// load default environment
envy.config = config[config.environment];

// Overwrite properties
if (process.env.NODE_ENV && config[process.env.NODE_ENV]) {
for (var property in config[process.env.NODE_ENV]) {
envy.config[property] = config[process.env.NODE_ENV][property];
}
}

};

envy.load('./config.json');

0 comments on commit e741c57

Please sign in to comment.