Skip to content

Instantly share code, notes, and snippets.

@flesch
Last active January 28, 2018 04:05
Show Gist options
  • Save flesch/333c4fac79f302d411365927ca06d328 to your computer and use it in GitHub Desktop.
Save flesch/333c4fac79f302d411365927ca06d328 to your computer and use it in GitHub Desktop.

@flesch/env-json

Inject env.json into process.env.

Install

$ npm install --save gist:333c4fac79f302d411365927ca06d328

Usage

const { NODE_ENV = 'development' } = require('@flesch/env-json')();
const { NODE_ENV = 'development' } = require('@flesch/env-json')('./development.env.json');
console.log(NODE_ENV);
console.log(process.env);
const { resolve } = require('path');
const root = resolve(__dirname, '../../../');
module.exports = (file = './env.json') => {
process.env = { ...require(resolve(root, file)), ...process.env };
return process.env;
};
'use strict';var _extends=Object.assign||function(a){for(var c,b=1;b<arguments.length;b++)for(var d in c=arguments[b],c)Object.prototype.hasOwnProperty.call(c,d)&&(a[d]=c[d]);return a},_require=require('path'),resolve=_require.resolve,root=resolve(__dirname,'../../../');module.exports=function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:'./env.json';return process.env=_extends({},require(resolve(root,a)),process.env),process.env};
{
"name": "@flesch/env-json",
"version": "1.0.0",
"main": "lib.js",
"author": "John Flesch <[email protected]>",
"license": "MIT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment