# dotenv-load

> Load environment variables from .env, .env.local, .env.production, etc. when running a npm or yarn command

Latest version **3.0.0** (published 2023-08-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install dotenv-load
pnpm add dotenv-load
yarn add dotenv-load
bun add dotenv-load
```

Provides the command `dotenv-load`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2023-08-02 |
| First published | 2018-03-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 3 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 40 |
| Author | Martin Rädlinger |
| Maintainers | formatlos |
| Keywords | dotenv, yarn, npm run |

## Links

- npm: https://www.npmjs.com/package/dotenv-load
- Repository: https://github.com/formatlos/dotenv-load
- Issues: https://github.com/formatlos/dotenv-load/issues
- npm.io page: https://npm.io/package/dotenv-load

## Dependencies (3)

- [dotenv](https://npm.io/package/dotenv.md) ^16.3.1
- [shelljs](https://npm.io/package/shelljs.md) ^0.8.5
- [dotenv-expand](https://npm.io/package/dotenv-expand.md) ^10.0.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2023-08-02
- 2.0.1 — 2022-03-17
- 2.0.0 — 2019-05-22
- 1.1.0 — 2018-07-03
- 1.0.0 — 2018-03-14

## README

# dotenv-load [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

Load environment variables from `.env`, `.env.local`, `.env.production`, etc. when running a npm or yarn command. 

This dotenv loading behaviour was extracted from [create-react-app](https://github.com/facebook/create-react-app) to be 
also usable with non `create-react-app` projects like [next.js](https://github.com/zeit/next.js/) or any other `node` 
specific project.

## Usage

### Use in yarn or npm commands

`dotenv-load` can be used in an yarn/npm command: 

```json
{
  "scripts": {
    "dev": "dotenv-load node server.js",
    "build": "NODE_ENV=production dotenv-load node server.js"
  }
}
```

### Use in node script

`dotenv-load` can be used in an yarn/npm command: 

```js
const dotenvLoad = require('dotenv-load');
dotenvLoad();
```

### ignore `.local` files

add `.local` files to `.gitignore`

```txt
.env.local
.env.development.local
.env.production.local
```

## What other .env* files can I use?

`dotenv-load` will load the following files, starting from the bottom. 
The first value set (or those already defined in the environment) take precedence:

- `.env` - The Original®
- `.env.local` - Local overrides. This file is loaded for all environments _except_ `test`.
- `.env.development`, `.env.test`, `.env.production` - Environment-specific settings.
- `.env.development.local`, `.env.test.local`, `.env.production.local` - Local overrides of environment-specific settings.

## How can I use custom env file?

You can pass a string to `dotenvLoad` function, but your file should have a name like `.env.YOUR_CUSTOM_NAME`, for example: `.env.default`.

Then you can initialize it as follows:

```js
dotenvLoad() # will initialize standard names
dotenvLoad('default') # will initialize your `.env.default` (while not overwriting defined vars above)
```

---
_Source: https://npm.io/package/dotenv-load · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
