env-dyn-config
v1.0.2
Published
Dynamic config files depending on env
Downloads
17
Maintainers
Readme
env-dyn-config
env-dyn-config is simple approach for dynamic configuration files. It breaks down the configuration depending on the environment distinguiting the base from the env's specifics.
Install
Recommended to install locally
npm install env-dyn-config --save
Or installing with yarn? yarn add env-dyn-config
Usage
1. Environment
Since this uses the dotenv package, create a .env
file in the root of your project:
NODE_ENV="development"
2. env-dyn-config intialization
Add the following file to initialize the module.
/// env-dyn-config.config.ts
import init from "env-dyn-config";
export default init();
3. Your first config
Add your config file.
/// config.ts
import edc from "./env-dyn-config.config";
const { combine, environments } = edc;
const specific = {
[environments.production]: {
property: "for your dear clients"
}
}
export default combine({
property: "for devs only"
}, specific);
NB: as early as possible in your application, import / configure env-dyn-config. Once imported, the returned value of each exported combine remains the same (since its cached).
For more examples see repo env-dyn-config-examples
Documentation
This package exposes a function, once runned, returning:
environments
the list of environment namesENV
the current environment recognized by dotenvfusion
a method to merge configurations