I am writing an NPM package that sets environment variables using process.env. Here is the code from the NPM package:
Object.keys(parsedObj).forEach((key) => {
process.env[key] = parsedObj[key];
});
In this file within the package I console.log process.env and see the variables set correctly. However, when I call this function in my code that imports this function, I console.log process.env and the variables are missing.
For context, here is the entire file: https://github.com/arsood/Cooler-Env/blob/master/loadEnv.js#L33
Does anyone have thoughts as to why these global variables are not available in the main code after running this function? Do modules run their own process? If so, is there a way to write environment variables to the main process from the package?