load-dotenv
Advanced tools
+3
-2
| { | ||
| "name": "load-dotenv", | ||
| "version": "0.0.7", | ||
| "version": "0.0.8", | ||
| "description": "Automatically load the closest .env file", | ||
@@ -36,3 +36,4 @@ "author": "Zach Olivare <https://github.com/0livare>", | ||
| "directory", | ||
| "search" | ||
| "search", | ||
| "monorepo" | ||
| ], | ||
@@ -39,0 +40,0 @@ "types": "./find.d.ts", |
+32
-6
@@ -5,2 +5,11 @@ # Load Dot ENV | ||
| ## Why? | ||
| By default the `dotenv` package only looks in the [current working directory][cwd] of the Node.js process for a `.env` file. And if you use the [path] option, that path must be identical both when running locally and when running in production. | ||
| Monorepos are a common example when it may be convenient to have a `.env` file that is not in your CWD. `load-dotenv` allows you to have a single `.env` file used by every package, regardless of file structure. | ||
| [cwd]: https://nodejs.org/api/process.html#processcwd | ||
| [path]: https://github.com/motdotla/dotenv#path | ||
| ## Install | ||
@@ -16,3 +25,3 @@ | ||
| Add this import before any other import in your project: | ||
| As early as possible in your application, import `load-dotenv/load`: | ||
@@ -23,2 +32,8 @@ ```js | ||
| Or in Common JS: | ||
| ```js | ||
| require('load-dotenv/load') | ||
| ``` | ||
| ## Or load it yourself | ||
@@ -28,12 +43,23 @@ | ||
| import {findEnv} from 'load-dotenv' | ||
| import * as dotenv from 'dotenv' | ||
| const envFile = findEnv() | ||
| require('dotenv').config({path: envFile}) | ||
| const envFilePath = findEnv() | ||
| dotenv.config({path: envFilePath}) | ||
| ``` | ||
| Or with a custom name | ||
| Or in Common JS: | ||
| ```js | ||
| const envFile = findEnv('.env.local') | ||
| require('dotenv').config({path: envFile}) | ||
| const {findEnv} = require('load-dotenv') | ||
| const dotEnv = require('dotenv') | ||
| const envFilePath = findEnv() | ||
| dotEnv.config({path: envFilePath}) | ||
| ``` | ||
| Or with a custom name: | ||
| ```js | ||
| const envFilePath = findEnv('.env.local') | ||
| dotenv.config({path: envFilePath}) | ||
| ``` |
13928
6.52%62
72.22%