Skip to content

Instantly share code, notes, and snippets.

@ooooak

ooooak/main.js

Created Feb 7, 2017
Embed
What would you like to do?
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