dotenv-config
v0.1.1
Published
Module that loads environment variables and verify their presence
Downloads
2,338
Maintainers
Readme
dotenv-config
Module that loads environment variables and verify their presence
How to use it
This module requires config
file that look like this:
config.json
{
"test": {
"require": true,
"env": "HOST"
},
"port": "PORT",
"default": {
"require": true,
"env": "DEFAULT",
"default": "default value"
}
}
and optionally .env
file with saved environment variables:
.env
HOST=localhost
PORT=4000
Usage:
index.js
const config = require('dotenv-config')();
console.log(config.test); // localhost
module.exports = config;
Additional settings
const config = require('dotenv-config');
const settings = {
envPath: '.env', // relative to project path
configPath: 'config.json' // relative to project path
};
config(settings);
Setting default routes
It is possible to change the default paths to config
and .env
by setting this environment variables:
DOTENV_CONFIG_ENVFILE=default/path/to/env/file
DOTENV_CONFIG_CONFIGFILE=default/path/to/config/file