dotenv-config

Module that loads environment variables and verify their presence


Keywords
.env, env, dotenv, config, configuration, settings, environment, variables, config-management, environment-variables, npm-module
License
GPL-3.0-only
Install
npm install dotenv-config@0.1.1

Documentation

dotenv-config

npm version node Build Status codecov Code Style License: GPL v3

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