How can I set an environmental variable in node.js?
I would prefer not to rely on anything platform specific, such as running export or cmd.exe's set.
You can set your environment variables in
process.env['VARIABLE'] = 'value';
Node should take care of the platform specifics.
First you should install this package :-
npm install dotenv]
Then you need to create a .env file in your project's root directory, and there you can add variables like below:-
Now you can easily access these variables in your code like below:-
It worked for me, hopefully that helps.