I've looked into things like dotenv and get the concept of environment variables, the part I am missing is where and when the detection of which variable to use happens. To be specific I'm dealing with the Stripe API key and of course, I want to use the Test API key when I'm developing locally and then the Live API key when I push to production.
So obviously I'll have a .env file with something like;
test_API_KEY=1234
live_API_KEY=5678
But then surely somewhere in my code I need something like
var keyToUse;
if(productionEnvironment){
keyToUse = process.env.live_API_KEY
}
else if(!productionEnvironment){
keyToUse = process.env.test_API_KEY
}
Or does like dotenv (or secure dot env) manage that for you? Or is this done with another tool/technique?
Thanks in advance