dwyl/env2

Feature: Return env as Object

Opened this issue · 0 comments

Story

As a person wanting to know which which environment variables were in the .env file
I would like to have the environment variables that were in the .env file returned as an Object
So that I can check if the var was loaded from a file or from another place.

Currently in our usage instructions: https://github.com/dwyl/env2#use-in-your-code
image
We hint at the possibility that the environment variables loaded by env2
are assigned to the env constant:

const env = require('env2')('./path-to-your/.env');

But reading the code we can see that no such Object is being returned:

env2/lib/env.js

Lines 57 to 60 in 15a8bd4

console.warn(msg);
return msg;
}
};

We could return the env on line 38 and it would (before the catch statement):

env2/lib/env.js

Lines 32 to 38 in 15a8bd4

var env = env_getter(filepath);
Object.keys(env).forEach(function(k) {
if(!process.env[k]) { // allow enviroment to take precedence over env.json
process.env[k] = env[k]; // only set if not set by environment
}
});
}

This would not alter the existing functionality of the package and would add this feature.