detect-environment
Version:
Detect environments in JavaScript similar to the way Laravel does
57 lines (41 loc) • 972 B
JavaScript
var
//
fs = require('fs'),
//
createPathsArray = require('./createPathsArray'),
/**
*
*/
readEnvFile = function readEnvFile (options, envName) {
//
if (options.strict !== true) {
options.strict = false;
}
//
if (!envName || typeof envName !== 'string') {
throw new TypeError('readEnvFile:');
}
var
//
pathsArr = createPathsArray(options, envName),
//
path = pathsArr.shift();
//
while (path) {
//
if (fs.existsSync(path)) {
return fs.readFileSync(path).toString();
}
//
path = pathsArr.shift();
}
//
if (options.strict) {
throw new Error('readEnvFile:');
}
//
return '';
};
// Expose to node.js
module.exports = readEnvFile;
;