I am relatively new to Node.js. I want to export environment variables from .env file to my javascript files. In order to do that I am using dotenv.
Which method should I use to export the environment variables to my main javascript files ( say- app.js)
export GEOCODER_API_KEY= someKeyXYZ // inside .env file
GEOCODER_API_KEY_1 = someKeyXYZ // inside .env file
One thing to note is that upon console.log(process.env) in the app.js, the GEOCODER_API_KEY_1 shows up as env variable, but not GEOCODER_API_KEY? Why is that. What use is the first one then, since it is not accessible? A more confusing thing is that:
var options = {
provider: 'google',
httpAdapter: 'https',
apiKey: process.env.GEOCODER_API_KEY,
formatter: null
}; // this works
... // some javascript
console.log(process.env.GEOCODER_API_KEY) //SHOWS UNDEFINED
I basically want to export the API_KEY (unrestricted) safely to my project. Is there a catch that I might be missing?