diff --git a/lib/main.js b/lib/main.js index eb96e7fd..5da0ea71 100644 --- a/lib/main.js +++ b/lib/main.js @@ -60,7 +60,9 @@ function config (options) { var parsedObj = parse(fs.readFileSync(path, { encoding: encoding })) Object.keys(parsedObj).forEach(function (key) { - process.env[key] = process.env[key] || parsedObj[key] + if (!process.env.hasOwnProperty(key)) { + process.env[key] = parsedObj[key] + } }) return { parsed: parsedObj } diff --git a/test/main.js b/test/main.js index 7d6c3cf1..f373ed50 100644 --- a/test/main.js +++ b/test/main.js @@ -74,6 +74,15 @@ describe('dotenv', function () { done() }) + it('does not write over keys already in process.env if the key has a falsy value', function (done) { + process.env.test = '' + // 'val' returned as value in `beforeEach`. should keep this '' + dotenv.config() + + process.env.test.should.eql('') + done() + }) + it('returns parsed object', function (done) { var env = dotenv.config()