I want to work with environment variables. Unfortunately, I am an inexperienced developer and decided very late to implement such a solution in my project.
I'm trying to inject environment variables, located in .env file, to all JS files (not all of them using environment variables, but I thought it would be faster and easier). Currently, I'm using dotenv package but it is obviously working in one file at once.
Should I use dotenv the standard way? Maybe there's a vulnerability I don't know of and that's why it is very unpopular to use environment variables this way.
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
You don't need to write require('dotenv').config() in every file. Just include this as the top statement in the index.js or the main file that got executed at the very first place when you run your program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With