envpro
v1.0.1
Published
Library to load the environment configuration.
Downloads
1
Maintainers
Readme
Introduction
A set of tools to get env files and save in memory of node process
Start
- Install
npm i envpro --save
- Use
const envpro = require('envpro');
const options =
{
global: true,
process: true,
dirname: __dirname,
defaultEnv:'dev',
envName: 'nodeRocks-1.0',
envPatterns:['dev','int','pre', 'pro'],
types:['json','js'],
excludeFiles:['package.json','index.js'],
excludeFolders:['node_modules']
};
const env = envpro.init(options);
OPTIONS FOR INIT METHOD
- example:
- global: true,
- process: true,
- dirname: 'custom_path/to/my/folder'
- defaultEnv: 'pre'
- envName: 'nodeRocks-1.0'
- envPatterns: ['dev','int','pre','pro']
- types:['json','js'],
- excludeFiles:['package.json','index.js'],
- excludeFolders:['node_modules','other_folder']
Global var env
Get the env context in other files after call goenv in index app.
const env = global[myEnvNameInstance];
Extend env
const envpro = require('envpro');
const optionsExtend =
{
global: true,
process: true,
envName: 'nodeRocks-1.0'
};
const extended = envpro.extend({
propertyExtended: {
property: 'extended'
}
}, optionsExtend);
console.log('extended',global['nodeRocks-1.0']);
Added method to remove deep properties
const deleteOptions = {
global: true,
process: true,
envName: 'nodeRocks-1.0',
key: 'credentials'
};
const deleted = envpro.deleteProps(deleteOptions);
OPTIONS FOR deleteProps METHOD
- example:
- global: true,
- process: true,
- envName: 'nodeRocks-1.0',
- key: 'credentials'
Added method to write an env file
let optionsWriteFile ={
filename: 'myEnvFile',
path: __dirname,
envName: 'nodeRocks-1.0',
global:true
};
envpro.writeEnvFile(optionsWriteFile, (err,done)=>
{
if(err)
{
console.log(err);
};
console.log(done);
});
OPTIONS FOR writeEnvFile METHOD
- example:
- filename: 'myEnvFile',
- path: 'path/to/save/the/envFile'
- envName: 'nodeRocks-1.0',
- global:true
- process: false