in this blog, I am going to share how you can use your APi's PORTS, Hash Secrets in node.js by using environment variables.
1) Install dotenv by running this command in node.js terminal npm install dotenv
2) Creat new .env file name should b .env you will see an gear icon
3) define secret values and variables like the bellow snippet. follow exact same patter don't use "Quotes for strings"
4) require it in the root of the application. before calling any route it's good practice to use it ASAP. also call config for configuration of.env variables
5) Finally use it anywhere in the application by using process.env.variableName see example bellow
That's all for using .env in node.js. this is my first post on dev.to . please leave your feedback about this blog. (this is my first blog/tutorial post ).
Saad Abbasi (MEAN stack Dev)