Categories
JavaScript Answers

How to toggle between multiple .env files like .env.development with Node.js?

Spread the love

To toggle between multiple .env files like .env.development with Node.js, we use the dotenv library.

For instance, we write

require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` });

to call config with an object with the path property to point to the .env file path we want to use.

process.env.NODE_ENV is the NODE_ENV environment variable value.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *