ja-environment
v0.0.13
Published
Just another environment manager
Downloads
2
Maintainers
Readme
Install
npm install --save ja-environment
or
yarn install ja-environment
Import module
const { JAEnvironment, JsonFileProvider } = require('ja-environment');
or
import { JAEnvironment, JsonFileProvider } from 'ja-environment';
Usage
Configuration files by default should be located in __environment__ folder with following structure:
- default.json
- development.json
- test.json
- any_other.json
All files are optional
You can automatically encrypt any key of json by add ! in key name.
Example:
example.json
{
"default": "it is a default",
"!secret": "secret",
"section": {
"!secret": "secret value"
}
}
example.jsone
{
"default": "it is a default",
"!secret": "21912fdb6fe67c40bd71e37da66adc7a290780861d0b5a2499be846a7076e4b731323334353637383930414243444546a+ZlSuBolZ7wXGJKerZPiQ==",
"section": {
"!secret": "21912fdb6fe67c40bd71e37da66adc7a290780861d0b5a2499be846a7076e4b731323334353637383930414243444546a+ZlSuBolZ7wXGJKerZPiQ=="
}
}
Configure environment variables:
export NODE_ENV=development
export ENV_SECRET=1234567890ABCDEF # optional for encrypotor
Initialization:
const provider = new JsonFileProvider({});
const env = new JAEnvironment({
provider
});
env.init();
Usage:
console.log(env.get("section.secret")); //output is "secret value"
More examples you can find in tests
Build
npm run build // for single build
npm run watch // to watch changes
or
yarn build // for single build
yarn watch // to watch changes
Author
License
ISC License
Copyright (c) 2020 Sergey Frangulov
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.