diff --git a/lib/main.js b/lib/main.js index eb96e7fd..ea4db067 100644 --- a/lib/main.js +++ b/lib/main.js @@ -58,12 +58,16 @@ function config (options) { try { // specifying an encoding returns a string instead of a buffer var parsedObj = parse(fs.readFileSync(path, { encoding: encoding })) + var insertedObj = {} Object.keys(parsedObj).forEach(function (key) { - process.env[key] = process.env[key] || parsedObj[key] + var value = process.env[key] || parsedObj[key] + + insertedObj[key] = value + process.env[key] = value }) - return { parsed: parsedObj } + return { parsed: parsedObj, inserted: insertedObj } } catch (e) { return { error: e } } diff --git a/test/main.js b/test/main.js index 7d6c3cf1..89b7bc3d 100644 --- a/test/main.js +++ b/test/main.js @@ -82,6 +82,14 @@ describe('dotenv', function () { done() }) + it('returns inserted object', function (done) { + var env = dotenv.config() + + env.should.not.have.property('error') + env.inserted.should.eql({ test: 'val' }) + done() + }) + it('returns any errors thrown from reading file or parsing', function (done) { readFileSyncStub.throws()