What is dotenv in express?

Hello everyone!

I’m currently watching Beau Carnes mern stack tutorial. I’m a bit unsure about dotenv, and what why it is necessary? Can anyone who knows explain it to me?

It’s a library (well, basically a script) that lets you write environment variables for your app in a file called .env (hence why it’s called dotenv). It means you don’t have to add them to your environment yourself. An environment variable is a value you save to somewhere on the operating system that is available to processes running on the system. Environment variables are nothing to do specifically with JS, it’s just a useful place to put things like API keys, stuff that only lives on one specific machine (yours for example). Then in your app you can use those environment variables. When you build your app the references to the environment variables will be replaced with the actual values stored on the system you’re building it on. There are versions of the dotenv library for most other languages, they all do the same thing.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.