call-a3 / dynamic-dotenv

A version of dotenv that will watch the dotenv file and reload it if it changes
MIT License
1 stars 1 forks source link

dynamic-dotenv

NPM Travis Codecov Greenkeeper badge David David Dev

Like dotenv, but dynamic!

Installing

# npm
npm install -s dynamic-dotenv

# yarn
yarn add dynamic-dotenv

Usage

This package essentially behaves the same as using the manual initialisation of the dotenv package. The main difference to dotenv, is that the response value is an EventEmitter. It will emit "change" events every time the loaded env file changes, as well as update the process.env values when that happens. If an error occurs, either from filesystem interaction or from dotenv, it will also be emitted as an "error" event.

import dynamicDotenv from 'dynamic-dotenv'

const dd = dynamicDotenv(/* you can pass the same options as dotenv here */)
// process.env now contains the values in your .env file

dd.on('change', () => {
  // this event will be emitted every time the .env file changes
})