wrap-env 16.3.3 → 16.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/README.md +639 -1
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -1 +1,639 @@
1
- This package is an wrap of `dotenv`
1
+ ### Note: This package is an wrap of `dotenv`
2
+
3
+ <div align="center">
4
+
5
+ <sup>Special thanks to:</sup>
6
+ <br>
7
+ <br>
8
+ <a href="https://www.warp.dev/?utm_source=github&utm_medium=referral&utm_campaign=dotenv_p_20220831">
9
+
10
+ <div>
11
+ <img src="https://res.cloudinary.com/dotenv-org/image/upload/v1661980709/warp_hi8oqj.png" width="230" alt="Warp">
12
+ </div>
13
+ <b>Warp is a blazingly fast, Rust-based terminal reimagined to work like a modern app.</b>
14
+ <div>
15
+ <sup>Get more done in the CLI with real text editing, block-based output, and AI command search.</sup>
16
+ </div>
17
+ </a>
18
+ <br>
19
+ <a href="https://retool.com/?utm_source=sponsor&utm_campaign=dotenv">
20
+ <div>
21
+ <img src="https://res.cloudinary.com/dotenv-org/image/upload/c_scale,w_300/v1664466968/logo-full-black_vidfqf.png" width="270" alt="Retool">
22
+ </div>
23
+ <b>Retool helps developers build custom internal software, like CRUD apps and admin panels, really fast.</b>
24
+ <div>
25
+ <sup>Build UIs visually with flexible components, connect to any data source, and write business logic in JavaScript.</sup>
26
+ </div>
27
+ </a>
28
+ <br>
29
+ <a href="https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=dotenv&utm_source=github">
30
+ <div>
31
+ <img src="https://res.cloudinary.com/dotenv-org/image/upload/c_scale,w_400/v1665605496/68747470733a2f2f73696e647265736f726875732e636f6d2f6173736574732f7468616e6b732f776f726b6f732d6c6f676f2d77686974652d62672e737667_zdmsbu.svg" width="270" alt="WorkOS">
32
+ </div>
33
+ <b>Your App, Enterprise Ready.</b>
34
+ <div>
35
+ <sup>Add Single Sign-On, Multi-Factor Auth, and more, in minutes instead of months.</sup>
36
+ </div>
37
+ </a>
38
+ <hr>
39
+ </div>
40
+
41
+ # dotenv [![NPM version](https://img.shields.io/npm/v/dotenv.svg?style=flat-square)](https://www.npmjs.com/package/dotenv)
42
+
43
+ <img src="https://raw.githubusercontent.com/motdotla/dotenv/master/dotenv.svg" alt="dotenv" align="right" width="200" />
44
+
45
+ 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](http://12factor.net/config) methodology.
46
+
47
+ [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
48
+ [![LICENSE](https://img.shields.io/github/license/motdotla/dotenv.svg)](LICENSE)
49
+ [![dotenv-vault](https://badge.dotenv.org/works-with.svg?r=1)](https://www.dotenv.org/r/github.com/dotenv-org/dotenv-vault?r=1)
50
+
51
+ - [🌱 Install](#-install)
52
+ - [🏗️ Usage (.env)](#%EF%B8%8F-usage)
53
+ - [🚀 Deploying (.env.vault) 🆕](#-deploying)
54
+ - [🌴 Multiple Environments 🆕](#-manage-multiple-environments)
55
+ - [📚 Examples](#-examples)
56
+ - [📖 Docs](#-documentation)
57
+ - [❓ FAQ](#-faq)
58
+ - [⏱️ Changelog](./CHANGELOG.md)
59
+
60
+ ## 🌱 Install
61
+
62
+ ```bash
63
+ # install locally (recommended)
64
+ npm install dotenv --save
65
+ ```
66
+
67
+ Or installing with yarn? `yarn add dotenv`
68
+
69
+ ## 🏗️ Usage
70
+
71
+ <a href="https://www.youtube.com/watch?v=YtkZR0NFd1g">
72
+ <div align="right">
73
+ <img src="https://img.youtube.com/vi/YtkZR0NFd1g/hqdefault.jpg" alt="how to use dotenv video tutorial" align="right" width="330" />
74
+ <img src="https://simpleicons.vercel.app/youtube/ff0000" alt="youtube/@dotenvorg" align="right" width="24" />
75
+ </div>
76
+ </a>
77
+
78
+ Create a `.env` file in the root of your project:
79
+
80
+ ```dosini
81
+ S3_BUCKET="YOURS3BUCKET"
82
+ SECRET_KEY="YOURSECRETKEYGOESHERE"
83
+ ```
84
+
85
+ As early as possible in your application, import and configure dotenv:
86
+
87
+ ```javascript
88
+ require("dotenv").config();
89
+ console.log(process.env); // remove this after you've confirmed it is working
90
+ ```
91
+
92
+ .. [or using ES6?](#how-do-i-use-dotenv-with-import)
93
+
94
+ ```javascript
95
+ import "dotenv/config";
96
+ ```
97
+
98
+ That's it. `process.env` now has the keys and values you defined in your `.env` file:
99
+
100
+ ```javascript
101
+ require('dotenv').config()
102
+
103
+ ...
104
+
105
+ s3.getBucketCors({Bucket: process.env.S3_BUCKET}, function(err, data) {})
106
+ ```
107
+
108
+ ### Multiline values
109
+
110
+ If you need multiline variables, for example private keys, those are now supported (`>= v15.0.0`) with line breaks:
111
+
112
+ ```dosini
113
+ PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
114
+ ...
115
+ Kh9NV...
116
+ ...
117
+ -----END RSA PRIVATE KEY-----"
118
+ ```
119
+
120
+ Alternatively, you can double quote strings and use the `\n` character:
121
+
122
+ ```dosini
123
+ PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nKh9NV...\n-----END RSA PRIVATE KEY-----\n"
124
+ ```
125
+
126
+ ### Comments
127
+
128
+ Comments may be added to your file on their own line or inline:
129
+
130
+ ```dosini
131
+ # This is a comment
132
+ SECRET_KEY=YOURSECRETKEYGOESHERE # comment
133
+ SECRET_HASH="something-with-a-#-hash"
134
+ ```
135
+
136
+ 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.
137
+
138
+ ### Parsing
139
+
140
+ 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.
141
+
142
+ ```javascript
143
+ const dotenv = require("dotenv");
144
+ const buf = Buffer.from("BASIC=basic");
145
+ const config = dotenv.parse(buf); // will return an object
146
+ console.log(typeof config, config); // object { BASIC : 'basic' }
147
+ ```
148
+
149
+ ### Preload
150
+
151
+ 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.
152
+
153
+ ```bash
154
+ $ node -r dotenv/config your_script.js
155
+ ```
156
+
157
+ The configuration options below are supported as command line arguments in the format `dotenv_config_<option>=value`
158
+
159
+ ```bash
160
+ $ node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/.env dotenv_config_debug=true
161
+ ```
162
+
163
+ Additionally, you can use environment variables to set configuration options. Command line arguments will precede these.
164
+
165
+ ```bash
166
+ $ DOTENV_CONFIG_<OPTION>=value node -r dotenv/config your_script.js
167
+ ```
168
+
169
+ ```bash
170
+ $ DOTENV_CONFIG_ENCODING=latin1 DOTENV_CONFIG_DEBUG=true node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/.env
171
+ ```
172
+
173
+ ### Variable Expansion
174
+
175
+ You need to add the value of another variable in one of your variables? Use [dotenv-expand](https://github.com/motdotla/dotenv-expand).
176
+
177
+ ### Syncing
178
+
179
+ You need to keep `.env` files in sync between machines, environments, or team members? Use [dotenv-vault](https://github.com/dotenv-org/dotenv-vault).
180
+
181
+ ### Deploying
182
+
183
+ You need to deploy your secrets in a cloud-agnostic manner? Use a `.env.vault` file.
184
+
185
+ ### Multiple Environments
186
+
187
+ You need to manage your secrets across different environments and apply them as needed? Use a `.env.vault` file with a `DOTENV_KEY`.
188
+
189
+ ## 🚀 Deploying
190
+
191
+ _Note: Requires dotenv >= 16.1.0_
192
+
193
+ Encrypt your `.env.vault` file.
194
+
195
+ ```bash
196
+ $ npx dotenv-vault build
197
+ ```
198
+
199
+ Fetch your production `DOTENV_KEY`.
200
+
201
+ ```bash
202
+ $ npx dotenv-vault keys production
203
+ ```
204
+
205
+ Set `DOTENV_KEY` on your server.
206
+
207
+ ```bash
208
+ # heroku example
209
+ heroku config:set DOTENV_KEY=dotenv://:key_1234…@dotenv.org/vault/.env.vault?environment=production
210
+ ```
211
+
212
+ That's it! On deploy, your `.env.vault` file will be decrypted and its secrets injected as environment variables – just in time.
213
+
214
+ _ℹ️ A note from [Mot](https://github.com/motdotla): Until recently, we did not have an opinion on how and where to store your secrets in production. We now strongly recommend generating a `.env.vault` file. It's the best way to prevent your secrets from being scattered across multiple servers and cloud providers – protecting you from breaches like the [CircleCI breach](https://techcrunch.com/2023/01/05/circleci-breach/). Also it unlocks interoperability WITHOUT native third-party integrations. Third-party integrations are [increasingly risky](https://coderpad.io/blog/development/heroku-github-breach/) to our industry. They may be the 'du jour' of today, but we imagine a better future._
215
+
216
+ <a href="https://github.com/dotenv-org/dotenv-vault#dotenv-vault-">Learn more at dotenv-vault: Deploying</a>
217
+
218
+ ## 🌴 Manage Multiple Environments
219
+
220
+ Edit your production environment variables.
221
+
222
+ ```bash
223
+ $ npx dotenv-vault open production
224
+ ```
225
+
226
+ Regenerate your `.env.vault` file.
227
+
228
+ ```bash
229
+ $ npx dotenv-vault build
230
+ ```
231
+
232
+ _ℹ️ 🔐 Vault Managed vs 💻 Locally Managed: The above example, for brevity's sake, used the 🔐 Vault Managed solution to manage your `.env.vault` file. You can instead use the 💻 Locally Managed solution. [Read more here](https://github.com/dotenv-org/dotenv-vault#how-do-i-use--locally-managed-dotenv-vault). Our vision is that other platforms and orchestration tools adopt the `.env.vault` standard as they did the `.env` standard. We don't expect to be the only ones providing tooling to manage and generate `.env.vault` files._
233
+
234
+ <a href="https://github.com/dotenv-org/dotenv-vault#-manage-multiple-environments">Learn more at dotenv-vault: Manage Multiple Environments</a>
235
+
236
+ ## 📚 Examples
237
+
238
+ See [examples](https://github.com/dotenv-org/examples) of using dotenv with various frameworks, languages, and configurations.
239
+
240
+ - [nodejs](https://github.com/dotenv-org/examples/tree/master/dotenv-nodejs)
241
+ - [nodejs (debug on)](https://github.com/dotenv-org/examples/tree/master/dotenv-nodejs-debug)
242
+ - [nodejs (override on)](https://github.com/dotenv-org/examples/tree/master/dotenv-nodejs-override)
243
+ - [nodejs (processEnv override)](https://github.com/dotenv-org/examples/tree/master/dotenv-custom-target)
244
+ - [nodejs (DOTENV_KEY override)](https://github.com/dotenv-org/examples/tree/master/dotenv-vault-custom-target)
245
+ - [esm](https://github.com/dotenv-org/examples/tree/master/dotenv-esm)
246
+ - [esm (preload)](https://github.com/dotenv-org/examples/tree/master/dotenv-esm-preload)
247
+ - [typescript](https://github.com/dotenv-org/examples/tree/master/dotenv-typescript)
248
+ - [typescript parse](https://github.com/dotenv-org/examples/tree/master/dotenv-typescript-parse)
249
+ - [typescript config](https://github.com/dotenv-org/examples/tree/master/dotenv-typescript-config)
250
+ - [webpack](https://github.com/dotenv-org/examples/tree/master/dotenv-webpack)
251
+ - [webpack (plugin)](https://github.com/dotenv-org/examples/tree/master/dotenv-webpack2)
252
+ - [react](https://github.com/dotenv-org/examples/tree/master/dotenv-react)
253
+ - [react (typescript)](https://github.com/dotenv-org/examples/tree/master/dotenv-react-typescript)
254
+ - [express](https://github.com/dotenv-org/examples/tree/master/dotenv-express)
255
+ - [nestjs](https://github.com/dotenv-org/examples/tree/master/dotenv-nestjs)
256
+ - [fastify](https://github.com/dotenv-org/examples/tree/master/dotenv-fastify)
257
+
258
+ ## 📖 Documentation
259
+
260
+ Dotenv exposes four functions:
261
+
262
+ - `config`
263
+ - `parse`
264
+ - `populate`
265
+ - `decrypt`
266
+
267
+ ### Config
268
+
269
+ `config` will read your `.env` file, parse the contents, assign it to
270
+ [`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env),
271
+ and return an Object with a `parsed` key containing the loaded content or an `error` key if it failed.
272
+
273
+ ```js
274
+ const result = dotenv.config();
275
+
276
+ if (result.error) {
277
+ throw result.error;
278
+ }
279
+
280
+ console.log(result.parsed);
281
+ ```
282
+
283
+ You can additionally, pass options to `config`.
284
+
285
+ #### Options
286
+
287
+ ##### path
288
+
289
+ Default: `path.resolve(process.cwd(), '.env')`
290
+
291
+ Specify a custom path if your file containing environment variables is located elsewhere.
292
+
293
+ ```js
294
+ require("dotenv").config({ path: "/custom/path/to/.env" });
295
+ ```
296
+
297
+ ##### encoding
298
+
299
+ Default: `utf8`
300
+
301
+ Specify the encoding of your file containing environment variables.
302
+
303
+ ```js
304
+ require("dotenv").config({ encoding: "latin1" });
305
+ ```
306
+
307
+ ##### debug
308
+
309
+ Default: `false`
310
+
311
+ Turn on logging to help debug why certain keys or values are not being set as you expect.
312
+
313
+ ```js
314
+ require("dotenv").config({ debug: process.env.DEBUG });
315
+ ```
316
+
317
+ ##### override
318
+
319
+ Default: `false`
320
+
321
+ Override any environment variables that have already been set on your machine with values from your .env file.
322
+
323
+ ```js
324
+ require("dotenv").config({ override: true });
325
+ ```
326
+
327
+ ##### processEnv
328
+
329
+ Default: `process.env`
330
+
331
+ Specify an object to write your secrets to. Defaults to `process.env` environment variables.
332
+
333
+ ```js
334
+ const myObject = {};
335
+ require("dotenv").config({ processEnv: myObject });
336
+
337
+ console.log(myObject); // values from .env or .env.vault live here now.
338
+ console.log(process.env); // this was not changed or written to
339
+ ```
340
+
341
+ ##### DOTENV_KEY
342
+
343
+ Default: `process.env.DOTENV_KEY`
344
+
345
+ Pass the `DOTENV_KEY` directly to config options. Defaults to looking for `process.env.DOTENV_KEY` environment variable. Note this only applies to decrypting `.env.vault` files. If passed as null or undefined, or not passed at all, dotenv falls back to its traditional job of parsing a `.env` file.
346
+
347
+ ```js
348
+ require("dotenv").config({
349
+ DOTENV_KEY:
350
+ "dotenv://:key_1234…@dotenv.org/vault/.env.vault?environment=production",
351
+ });
352
+ ```
353
+
354
+ ### Parse
355
+
356
+ The engine which parses the contents of your file containing environment
357
+ variables is available to use. It accepts a String or Buffer and will return
358
+ an Object with the parsed keys and values.
359
+
360
+ ```js
361
+ const dotenv = require("dotenv");
362
+ const buf = Buffer.from("BASIC=basic");
363
+ const config = dotenv.parse(buf); // will return an object
364
+ console.log(typeof config, config); // object { BASIC : 'basic' }
365
+ ```
366
+
367
+ #### Options
368
+
369
+ ##### debug
370
+
371
+ Default: `false`
372
+
373
+ Turn on logging to help debug why certain keys or values are not being set as you expect.
374
+
375
+ ```js
376
+ const dotenv = require("dotenv");
377
+ const buf = Buffer.from("hello world");
378
+ const opt = { debug: true };
379
+ const config = dotenv.parse(buf, opt);
380
+ // expect a debug message because the buffer is not in KEY=VAL form
381
+ ```
382
+
383
+ ### Populate
384
+
385
+ The engine which populates the contents of your .env file to `process.env` is available for use. It accepts a target, a source, and options. This is useful for power users who want to supply their own objects.
386
+
387
+ For example, customizing the source:
388
+
389
+ ```js
390
+ const dotenv = require("dotenv");
391
+ const parsed = { HELLO: "world" };
392
+
393
+ dotenv.populate(process.env, parsed);
394
+
395
+ console.log(process.env.HELLO); // world
396
+ ```
397
+
398
+ For example, customizing the source AND target:
399
+
400
+ ```js
401
+ const dotenv = require("dotenv");
402
+ const parsed = { HELLO: "universe" };
403
+ const target = { HELLO: "world" }; // empty object
404
+
405
+ dotenv.populate(target, parsed, { override: true, debug: true });
406
+
407
+ console.log(target); // { HELLO: 'universe' }
408
+ ```
409
+
410
+ #### options
411
+
412
+ ##### Debug
413
+
414
+ Default: `false`
415
+
416
+ Turn on logging to help debug why certain keys or values are not being populated as you expect.
417
+
418
+ ##### override
419
+
420
+ Default: `false`
421
+
422
+ Override any environment variables that have already been set.
423
+
424
+ ### Decrypt
425
+
426
+ The engine which decrypts the ciphertext contents of your .env.vault file is available for use. It accepts a ciphertext and a decryption key. It uses AES-256-GCM encryption.
427
+
428
+ For example, decrypting a simple ciphertext:
429
+
430
+ ```js
431
+ const dotenv = require("dotenv");
432
+ const ciphertext =
433
+ "s7NYXa809k/bVSPwIAmJhPJmEGTtU0hG58hOZy7I0ix6y5HP8LsHBsZCYC/gw5DDFy5DgOcyd18R";
434
+ const decryptionKey =
435
+ "ddcaa26504cd70a6fef9801901c3981538563a1767c297cb8416e8a38c62fe00";
436
+
437
+ const decrypted = dotenv.decrypt(ciphertext, decryptionKey);
438
+
439
+ console.log(decrypted); // # development@v6\nALPHA="zeta"
440
+ ```
441
+
442
+ ## ❓ FAQ
443
+
444
+ ### Why is the `.env` file not loading my environment variables successfully?
445
+
446
+ Most likely your `.env` file is not in the correct place. [See this stack overflow](https://stackoverflow.com/questions/42335016/dotenv-file-is-not-loading-environment-variables).
447
+
448
+ Turn on debug mode and try again..
449
+
450
+ ```js
451
+ require("dotenv").config({ debug: true });
452
+ ```
453
+
454
+ You will receive a helpful error outputted to your console.
455
+
456
+ ### Should I commit my `.env` file?
457
+
458
+ No. We **strongly** recommend against committing your `.env` file to version
459
+ control. It should only include environment-specific values such as database
460
+ passwords or API keys. Your production database should have a different
461
+ password than your development database.
462
+
463
+ ### Should I have multiple `.env` files?
464
+
465
+ No. We **strongly** recommend against having a "main" `.env` file and an "environment" `.env` file like `.env.test`. Your config should vary between deploys, and you should not be sharing values between environments.
466
+
467
+ > In a twelve-factor app, env vars are granular controls, each fully orthogonal to other env vars. They are never grouped together as “environments”, but instead are independently managed for each deploy. This is a model that scales up smoothly as the app naturally expands into more deploys over its lifetime.
468
+ >
469
+ > – [The Twelve-Factor App](http://12factor.net/config)
470
+
471
+ ### What rules does the parsing engine follow?
472
+
473
+ The parsing engine currently supports the following rules:
474
+
475
+ - `BASIC=basic` becomes `{BASIC: 'basic'}`
476
+ - empty lines are skipped
477
+ - lines beginning with `#` are treated as comments
478
+ - `#` marks the beginning of a comment (unless when the value is wrapped in quotes)
479
+ - empty values become empty strings (`EMPTY=` becomes `{EMPTY: ''}`)
480
+ - inner quotes are maintained (think JSON) (`JSON={"foo": "bar"}` becomes `{JSON:"{\"foo\": \"bar\"}"`)
481
+ - whitespace is removed from both ends of unquoted values (see more on [`trim`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim)) (`FOO= some value ` becomes `{FOO: 'some value'}`)
482
+ - single and double quoted values are escaped (`SINGLE_QUOTE='quoted'` becomes `{SINGLE_QUOTE: "quoted"}`)
483
+ - single and double quoted values maintain whitespace from both ends (`FOO=" some value "` becomes `{FOO: ' some value '}`)
484
+ - double quoted values expand new lines (`MULTILINE="new\nline"` becomes
485
+
486
+ ```
487
+ {MULTILINE: 'new
488
+ line'}
489
+ ```
490
+
491
+ - backticks are supported (`` BACKTICK_KEY=`This has 'single' and "double" quotes inside of it.` ``)
492
+
493
+ ### What happens to environment variables that were already set?
494
+
495
+ By default, we will never modify any environment variables that have already been set. In particular, if there is a variable in your `.env` file which collides with one that already exists in your environment, then that variable will be skipped.
496
+
497
+ If instead, you want to override `process.env` use the `override` option.
498
+
499
+ ```javascript
500
+ require("dotenv").config({ override: true });
501
+ ```
502
+
503
+ ### How come my environment variables are not showing up for React?
504
+
505
+ Your React code is run in Webpack, where the `fs` module or even the `process` global itself are not accessible out-of-the-box. `process.env` can only be injected through Webpack configuration.
506
+
507
+ If you are using [`react-scripts`](https://www.npmjs.com/package/react-scripts), which is distributed through [`create-react-app`](https://create-react-app.dev/), it has dotenv built in but with a quirk. Preface your environment variables with `REACT_APP_`. See [this stack overflow](https://stackoverflow.com/questions/42182577/is-it-possible-to-use-dotenv-in-a-react-project) for more details.
508
+
509
+ If you are using other frameworks (e.g. Next.js, Gatsby...), you need to consult their documentation for how to inject environment variables into the client.
510
+
511
+ ### Can I customize/write plugins for dotenv?
512
+
513
+ Yes! `dotenv.config()` returns an object representing the parsed `.env` file. This gives you everything you need to continue setting values on `process.env`. For example:
514
+
515
+ ```js
516
+ const dotenv = require("dotenv");
517
+ const variableExpansion = require("dotenv-expand");
518
+ const myEnv = dotenv.config();
519
+ variableExpansion(myEnv);
520
+ ```
521
+
522
+ ### How do I use dotenv with `import`?
523
+
524
+ Simply..
525
+
526
+ ```javascript
527
+ // index.mjs (ESM)
528
+ import "dotenv/config"; // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
529
+ import express from "express";
530
+ ```
531
+
532
+ A little background..
533
+
534
+ > When you run a module containing an `import` declaration, the modules it imports are loaded first, then each module body is executed in a depth-first traversal of the dependency graph, avoiding cycles by skipping anything already executed.
535
+ >
536
+ > – [ES6 In Depth: Modules](https://hacks.mozilla.org/2015/08/es6-in-depth-modules/)
537
+
538
+ What does this mean in plain language? It means you would think the following would work but it won't.
539
+
540
+ `errorReporter.mjs`:
541
+
542
+ ```js
543
+ import { Client } from "best-error-reporting-service";
544
+
545
+ export default new Client(process.env.API_KEY);
546
+ ```
547
+
548
+ `index.mjs`:
549
+
550
+ ```js
551
+ // Note: this is INCORRECT and will not work
552
+ import * as dotenv from "dotenv";
553
+ dotenv.config();
554
+
555
+ import errorReporter from "./errorReporter.mjs";
556
+ errorReporter.report(new Error("documented example"));
557
+ ```
558
+
559
+ `process.env.API_KEY` will be blank.
560
+
561
+ Instead, `index.mjs` should be written as..
562
+
563
+ ```js
564
+ import "dotenv/config";
565
+
566
+ import errorReporter from "./errorReporter.mjs";
567
+ errorReporter.report(new Error("documented example"));
568
+ ```
569
+
570
+ Does that make sense? It's a bit unintuitive, but it is how importing of ES6 modules work. Here is a [working example of this pitfall](https://github.com/dotenv-org/examples/tree/master/dotenv-es6-import-pitfall).
571
+
572
+ There are two alternatives to this approach:
573
+
574
+ 1. Preload dotenv: `node --require dotenv/config index.js` (_Note: you do not need to `import` dotenv with this approach_)
575
+ 2. Create a separate file that will execute `config` first as outlined in [this comment on #133](https://github.com/motdotla/dotenv/issues/133#issuecomment-255298822)
576
+
577
+ ### Why am I getting the error `Module not found: Error: Can't resolve 'crypto|os|path'`?
578
+
579
+ You are using dotenv on the front-end and have not included a polyfill. Webpack < 5 used to include these for you. Do the following:
580
+
581
+ ```bash
582
+ npm install node-polyfill-webpack-plugin
583
+ ```
584
+
585
+ Configure your `webpack.config.js` to something like the following.
586
+
587
+ ```js
588
+ require("dotenv").config();
589
+
590
+ const path = require("path");
591
+ const webpack = require("webpack");
592
+
593
+ const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
594
+
595
+ module.exports = {
596
+ mode: "development",
597
+ entry: "./src/index.ts",
598
+ output: {
599
+ filename: "bundle.js",
600
+ path: path.resolve(__dirname, "dist"),
601
+ },
602
+ plugins: [
603
+ new NodePolyfillPlugin(),
604
+ new webpack.DefinePlugin({
605
+ "process.env": {
606
+ HELLO: JSON.stringify(process.env.HELLO),
607
+ },
608
+ }),
609
+ ],
610
+ };
611
+ ```
612
+
613
+ Alternatively, just use [dotenv-webpack](https://github.com/mrsteele/dotenv-webpack) which does this and more behind the scenes for you.
614
+
615
+ ### What about variable expansion?
616
+
617
+ Try [dotenv-expand](https://github.com/motdotla/dotenv-expand)
618
+
619
+ ### What about syncing and securing .env files?
620
+
621
+ Use [dotenv-vault](https://github.com/dotenv-org/dotenv-vault)
622
+
623
+ ### What is a `.env.vault` file?
624
+
625
+ A `.env.vault` file is an encrypted version of your development (and ci, staging, production, etc) environment variables. It is paired with a `DOTENV_KEY` to deploy your secrets more securely than scattering them across multiple platforms and tools. Use [dotenv-vault](https://github.com/dotenv-org/dotenv-vault) to manage and generate them.
626
+
627
+ ## Contributing Guide
628
+
629
+ See [CONTRIBUTING.md](CONTRIBUTING.md)
630
+
631
+ ## CHANGELOG
632
+
633
+ See [CHANGELOG.md](CHANGELOG.md)
634
+
635
+ ## Who's using dotenv?
636
+
637
+ [These npm modules depend on it.](https://www.npmjs.com/browse/depended/dotenv)
638
+
639
+ Projects that expand it often use the [keyword "dotenv" on npm](https://www.npmjs.com/search?q=keywords:dotenv).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrap-env",
3
- "version": "16.3.3",
3
+ "version": "16.3.4",
4
4
  "description": "Loads environment variables from .env file",
5
5
  "main": "lib/main.js",
6
6
  "types": "lib/main.d.ts",
@@ -13,6 +13,7 @@
13
13
  "./config": "./config.js",
14
14
  "./config.js": "./config.js",
15
15
  "./lib/env-options": "./lib/env-options.js",
16
+ "./lib/sys.env": "./lib/sys.env.js",
16
17
  "./lib/env-options.js": "./lib/env-options.js",
17
18
  "./lib/cli-options": "./lib/cli-options.js",
18
19
  "./lib/cli-options.js": "./lib/cli-options.js",