0.1.1 • Published 5 years ago

dotenv-config v0.1.1

Weekly downloads
198
License
GPL-3.0-only
Repository
github
Last release
5 years ago

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