Video Course

Create a CRUD App with Node and MongoDB: Lesson 7 of 17

Environment Variables

Up Next

A Mongoose Model

Autoplaying in 7 seconds!

Cancel

We'll be using a handy package called dotenv to bring all environment variables in a .env file into our project.

Once we configure the package using:

require('dotenv').config();

We are able to call any variables from the environment using:

process.env.<variable_name>

process.env.DB_URI

It's common practice to keep environment variable names fully uppercase.

Note: Be sure to add .env to your .gitignore so that it doesn't get committed to your repo. Keep secret info out of public repos!

Chris Sevilleja

162 posts

Co-founder of Scotch.io. Slapping the keyboard until something good happens.