Environment variables in Node.js

Environment variables are fundamental part of developing Node.js. They allow your app to behave in differing ways based on the environment you want them to run in. If told in a more simple way environment variables help you to run your app anywhere without changing the code. To read environment variables you can use process.env. Process.env property returns an object containing the user environment.

process.env.ENV_VARIABLE

ENV_VARIABLE is the name of variable you want to access. It will not work in React.js. You can use env package to manage environment variables. Create a .env file and add all your variables in that. Then add the below line of code at the top of your application entry file.

require('dotenv').config();