dotenv-config

0.1.1 • Public • Published

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

Package Sidebar

Install

npm i dotenv-config

Weekly Downloads

373

Version

0.1.1

License

GPL-3.0-only

Unpacked Size

65 kB

Total Files

21

Last publish

Collaborators

  • tetrash