Skip to main content

Posts

Showing posts with the label dotenv

How to handle multiple environments in the Node.js framework?

There are multiple ways to achieve it but one of the simplest ways is to use the Dotenv module. Dotenv is a lightweight and zero-dependency module that automatically loads environment variables from a .env file into the process.env object. Handling multiple environments using dotenv involves creating separate .env files for each environment (e.g., dev, testing, staging, production) and dynamically loading the appropriate file based on the current environment. Here's a step-by-step guide to follow:          Step 1: Install dotenv Package (recommended- locally):           npm install dotenv --save          Step 2: Create separate .env files for each environment. For example:         .env.dev for development         .env.test for testing         .env.stage for staging         .env.prod for production   ...