Leaving aside public variables and focusing on backend ones.
When I access a variable (e.g. procee.env.ENVIRON) from server.ts file, I can read the value.
When I do the same in my custom core code (called inside custom endpoint inside server.ts file) it is undefined. These variables are not accessed by front-end.
server.ts
import { processGetAccountDetails } from './core/vault/controller';
console.log("server | ENVIRON: ", process.env.ENVIRON) // works
router.get('/vault/accounts', (req: any, res) => {
processGetAccountDetails(req,res)
});
/vault/controller/index.ts
require('dotenv').config();
console.log("vault controller | ENVIRON: ", process.env.ENVIRON) // undefined
This happens seemingly at random. Some files it works, other not. What am I missing?
I must add, this is only an issue in production, locally all works as expected.