relax-env-json
v0.0.4
Published
Environment management helper. More info: https://github.com/qx57/relax-env-json
Downloads
5
Maintainers
Readme
relax-env-json
Requirements
- node.js ^17.9.0
Dependencies
- @types/node ^17.0.41
Summary
This pack help you set your test environments so easy. Just create in root path environments.json like this:
{
"deafult": {
// Some your settings
}
}
and enjoy!
Get started
- install relax-env-json:
> npm i relax-env-json
- create in root path environments.json:
{
"default": {
"foo": "bar",
"isEnabled": true,
...
"someObj": {
...
}
}
}
More info below.
- add requirement into your test:
const env = require('relax-env-json');
let defaultEnvironment = env.getEnvironment();
- use your environment settings:
defaultEnvironment.foo; // = "bar"
Advanced settings
Different environment files usage
You can include various files, not only environment.json. For use anoither env file set process variable file:
> env file=another/environmen/file.json mocha test.js
Set default environment name
For set environment name dofferent than default you can use defaultEnvName field in env file:
{
"defaultEnvName": "myEnv",
...
"myEnv": {
// some your settings
}
}
Switch environments through cli
You can use process variable name for it:
> env name=myEnv mocha test.js
Switch environments in runtime
If you want to get variables from another environment you have two ways:
- you may get variables without environment switch:
anotherEnv = env.getEnvironmentByName('myEnv');
- or you can set new default environment:
defaultEnvironment = env.setEnvironment('myEnv');
Environments.json format
{
"defaultEnvName": string (optional, if no default field - required)
"default": any (required, if used defaultEnvName - optional)
"another-environment": any (optional)
}