Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

econf

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

econf - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.econf.js

60

lib/index.js
var fs = require('fs'),
util = require('util');
util = require('util'),
colors = require('colors');

@@ -84,2 +85,59 @@

}
}
module.exports.showEconfContent = function(cb) {
var path = process.cwd() + '/.econf.js';
fs.stat(path, function(err) {
if (err) {
console.log('File .econf.js not found'.red);
console.log('To create .econf.js execute:'.yellow, 'econf init');
return;
}
var objects = require(path);
objects = processHierarchy(objects);
for(property in objects) {
var object = objects[property];
var _extend = '';
if (object._extend) {
_extend = [].concat(object._extend);
_extend = _extend.join(', ');
_extend = '{' + _extend + '}';
}
console.log('');
console.log(property.green, _extend.yellow);
delete object._name;
delete object._extend;
console.log(' ', JSON.stringify(object, null, ' ').replace(/\n/g, '\n ').grey);
}
if (cb) {
cb();
}
})
}
module.exports.createEconfFile = function() {
var file = fs.readFileSync(__dirname + '/../.econf.js');
fs.writeFileSync(process.cwd() + '/.econf.js', file);
module.exports.showEconfContent(function() {
console.log('');
console.log('###########################################'.yellow);
console.log('### Do not forget to install econf lib ###'.yellow);
console.log('### ###'.yellow);
console.log('###'.yellow, 'npm install econf --save ', '###'.yellow);
console.log('### ###'.yellow);
console.log('### Do not forget to include econf lib ###'.yellow);
console.log('### into your project at the first line ###'.yellow);
console.log('### ###'.yellow);
console.log('###'.yellow, 'require("econf")() ', '###'.yellow);
console.log('### ###'.yellow);
console.log('###########################################'.yellow);
});
}
{
"name": "econf",
"version": "0.0.1",
"version": "0.0.2",
"description": "Load configs from hierarchical objects to process.env",

@@ -11,3 +11,11 @@ "scripts": {

"license": "MIT",
"main" : "./lib/index.js"
"main": "./lib/index.js",
"bin": {
"econf": "bin/econf.js"
},
"preferGlobal": "false",
"dependencies": {
"commander": "~2.1.0",
"colors": "~0.6.2"
}
}

@@ -24,2 +24,59 @@ econf

require('econf')('config.js');
```
```
#.econf.js example
```javascript
module.exports = [
{
_name: 'newrelic',
NEW_RELIC_KEY: 'key'
},
{
_name: 'production',
NAME: 'Production Base',
AWS_SECRET: 'aws-secret',
AWS_KEY: 'aws-key',
EMAIL_DELAY: 1000
},
{
_name: 'production.001',
_extend: ['production', 'newrelic'],
NAME: 'Production 001',
EMAIL_DELAY: 0
}
]
```
The config above will inject the code below into process.env
```javascript
{
"_name": "production.001",
"_extend": [
"production",
"newrelic"
],
"NAME": "Production 001",
"EMAIL_DELAY": 0,
"AWS_SECRET": "aws-secret",
"AWS_KEY": "aws-key",
"NEW_RELIC_KEY": "key"
}
```
#Global Usage
```javascript
npm install econf -g
```
With global version you can view your config parsed, just execute econf into your project directory
```javascript
econf
```
![econf](img/econf.png)
To create a example .econf.js file into your project just execute econf init into your project directory
```javascript
econf init
```
![econf](img/econf-init.png)

2

test/index.js
process.env.NODE_ENV = 'production.001';
var env = require('../lib/index')();
console.log(JSON.stringify(process.env, null, ' '));
console.log(JSON.stringify(env, null, ' '));

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc