I am struggling with accessing process.env variables in my TypeScript pages. It seems to be a scope issue, which doesn't make sense to me as a beginner in TypeScript.
To get my environment variables, I use a YAML file and attach them to the running process.
module.exports = function() {
const YAML = require('yamljs');
const envVars = YAML.load('env.yml')[process.env.NODE_ENV];
Object.keys(envVars).forEach(v => {
console.log('vars', v);
process.env[v] = envVars[v];
});
};
To run my TypeScript code, I use the following npm command:
cross-env NODE_ENV=test node -e \"require('./setup-env')()\" && jasmine-ts **/*.spec.ts
Although I can see the values of each variable in the loadYmlEnv
, when I try to log them from my TypeScript files, they all come out as undefined. Even after checking the entire process.env
, I cannot find the necessary environment variables. This situation is quite perplexing to me.