Skip to content

Instantly share code, notes, and snippets.

@ooooak
Created February 7, 2017 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ooooak/347217a75fa41e4ad2bb21fbc10a5ebe to your computer and use it in GitHub Desktop.
Save ooooak/347217a75fa41e4ad2bb21fbc10a5ebe to your computer and use it in GitHub Desktop.
read laravel .env in node
var fs = require('fs');
var path = require('path');
function readEnv() {}
readEnv.prototype.get = function(index, other) {
var root = __dirname.replace('test' + path.sep + 'Libs', '');
var contents = fs.readFileSync(root + '.env', 'utf8').split("\n");
var obj = {};
for (var i = 0; i < contents.length; i++) {
var code = contents[i].replace('\r', '');
if (code.length) {
var chunk = code.split('=');
obj[chunk[0]] = chunk[1];
}
}
if (obj[index])
return obj[index];
else
return other;
}
module.exports = new readEnv();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment