Dotenv is supported by the community.

Special thanks to:

Warp
Warp is a blazingly fast, Rust-based terminal reimagined to work like a modern app.
Get more done in the CLI with real text editing, block-based output, and AI command search.

WorkOS
Your App, Enterprise Ready.
Add Single Sign-On, Multi-Factor Auth, and more, in minutes instead of months.

Alloy Automation
Launch user-facing integrations faster
Easily spin up hundreds of integrations. Sign up free or read our docs first

# dotenv [![NPM version](https://img.shields.io/npm/v/dotenv.svg?style=flat-square)](https://www.npmjs.com/package/dotenv) dotenv Dotenv is a zero-dependency module that loads environment variables from a `.env` file into [`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env). Storing configuration in the environment separate from code is based on [The Twelve-Factor App](https://12factor.net/config) methodology. [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) [![LICENSE](https://img.shields.io/github/license/motdotla/dotenv.svg)](LICENSE) [![dotenv-vault](https://badge.dotenv.org/works-with.svg?r=1)](https://www.dotenv.org/r/github.com/dotenv-org/dotenv-vault?r=1) * [🌱 Install](#-install) * [πŸ—οΈ Usage (.env)](#%EF%B8%8F-usage) * [🌴 Multiple Environments πŸ†•](#-manage-multiple-environments) * [πŸš€ Deploying (.env.vault) πŸ†•](#-deploying) * [πŸ“š Examples](#-examples) * [πŸ“– Docs](#-documentation) * [❓ FAQ](#-faq) * [⏱️ Changelog](./CHANGELOG.md) ## 🌱 Install ```bash # install locally (recommended) npm install dotenv --save ``` Or installing with yarn? `yarn add dotenv` ## πŸ—οΈ Usage
how to use dotenv video tutorial youtube/@dotenvorg
Create a `.env` file in the root of your project: ```dosini S3_BUCKET="YOURS3BUCKET" SECRET_KEY="YOURSECRETKEYGOESHERE" ``` As early as possible in your application, import and configure dotenv: ```javascript require('dotenv').config() console.log(process.env) // remove this after you've confirmed it is working ``` .. [or using ES6?](#how-do-i-use-dotenv-with-import) ```javascript import 'dotenv/config' ``` That's it. `process.env` now has the keys and values you defined in your `.env` file: ```javascript require('dotenv').config() ... s3.getBucketCors({Bucket: process.env.S3_BUCKET}, function(err, data) {}) ``` ### Multiline values If you need multiline variables, for example private keys, those are now supported (`>= v15.0.0`) with line breaks: ```dosini PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY----- ... Kh9NV... ... -----END RSA PRIVATE KEY-----" ``` Alternatively, you can double quote strings and use the `\n` character: ```dosini PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nKh9NV...\n-----END RSA PRIVATE KEY-----\n" ``` ### Comments Comments may be added to your file on their own line or inline: ```dosini # This is a comment SECRET_KEY=YOURSECRETKEYGOESHERE # comment SECRET_HASH="something-with-a-#-hash" ``` Comments begin where a `#` exists, so if your value contains a `#` please wrap it in quotes. This is a breaking change from `>= v15.0.0` and on. ### Parsing The engine which parses the contents of your file containing environment variables is available to use. It accepts a String or Buffer and will return an Object with the parsed keys and values. ```javascript const dotenv = require('dotenv') const buf = Buffer.from('BASIC=basic') const config = dotenv.parse(buf) // will return an object console.log(typeof config, config) // object { BASIC : 'basic' } ``` ### Preload You can use the `--require` (`-r`) [command line option](https://nodejs.org/api/cli.html#-r---require-module) to preload dotenv. By doing this, you do not need to require and load dotenv in your application code. ```bash $ node -r dotenv/config your_script.js ``` The configuration options below are supported as command line arguments in the format `dotenv_config_