As early as possible in your application, require and configure dotenv-yaml.
require('dotenv-yaml').config();
You can use the --require
(-r
) command line option to preload dotenv-yaml. By doing this, you do not need to require and load dotenv-yaml in your application code.
$ node -r dotenv-yaml/config your_script.js
The configuration options below are supported as command line arguments in the format dotenv_yaml_config_<option>=value
$ node -r dotenv-yaml/config your_script.js dotenv_yaml_config_path=/custom/path/to/your/env/vars dotenv_yaml_config_encoding=utf8
Create a .env.yml
file in the root directory of your project,
and add environment-specific variables as valid YAML.
That's it.
process.env
now has the keys and values you defined in your .env.yml
file.
Default: .env.yml
You can specify a custom path if your file containing environmnet variables is named or located differently.
require('dotenv-yaml').config({ path: '/custom/path/to/your/yaml/env/vars' });
Default: utf8
You may specify the encoding of your file containing environment variables using this option.
require('dotenv-yaml').config({ encoding: 'base64' });