wrap-env 16.3.2 â 16.3.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +114 -108
- package/package.json +2 -1
- package/README-es.md +0 -1
package/README.md
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
+
### Note: This package is an wrap of `dotenv`
|
2
|
+
|
1
3
|
<div align="center">
|
2
4
|
|
3
|
-
<p>
|
4
|
-
<sup>
|
5
|
-
<a href="https://github.com/sponsors/motdotla">Dotenv is supported by the community.</a>
|
6
|
-
</sup>
|
7
|
-
</p>
|
8
5
|
<sup>Special thanks to:</sup>
|
9
6
|
<br>
|
10
7
|
<br>
|
11
8
|
<a href="https://www.warp.dev/?utm_source=github&utm_medium=referral&utm_campaign=dotenv_p_20220831">
|
9
|
+
|
12
10
|
<div>
|
13
11
|
<img src="https://res.cloudinary.com/dotenv-org/image/upload/v1661980709/warp_hi8oqj.png" width="230" alt="Warp">
|
14
12
|
</div>
|
@@ -48,16 +46,16 @@ Dotenv is a zero-dependency module that loads environment variables from a `.env
|
|
48
46
|
|
49
47
|
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
|
50
48
|
[![LICENSE](https://img.shields.io/github/license/motdotla/dotenv.svg)](LICENSE)
|
51
|
-
[![dotenv-vault](https://badge.dotenv.org/works-with.svg?r=1)](https://www.dotenv.org/r/github.com/dotenv-org/dotenv-vault?r=1)
|
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)
|
52
50
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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)
|
61
59
|
|
62
60
|
## đą Install
|
63
61
|
|
@@ -87,14 +85,14 @@ SECRET_KEY="YOURSECRETKEYGOESHERE"
|
|
87
85
|
As early as possible in your application, import and configure dotenv:
|
88
86
|
|
89
87
|
```javascript
|
90
|
-
require(
|
91
|
-
console.log(process.env) // remove this after you've confirmed it is working
|
88
|
+
require("dotenv").config();
|
89
|
+
console.log(process.env); // remove this after you've confirmed it is working
|
92
90
|
```
|
93
91
|
|
94
92
|
.. [or using ES6?](#how-do-i-use-dotenv-with-import)
|
95
93
|
|
96
94
|
```javascript
|
97
|
-
import
|
95
|
+
import "dotenv/config";
|
98
96
|
```
|
99
97
|
|
100
98
|
That's it. `process.env` now has the keys and values you defined in your `.env` file:
|
@@ -142,10 +140,10 @@ Comments begin where a `#` exists, so if your value contains a `#` please wrap i
|
|
142
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.
|
143
141
|
|
144
142
|
```javascript
|
145
|
-
const dotenv = require(
|
146
|
-
const buf = Buffer.from(
|
147
|
-
const config = dotenv.parse(buf) // will return an object
|
148
|
-
console.log(typeof config, config) // object { BASIC : 'basic' }
|
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' }
|
149
147
|
```
|
150
148
|
|
151
149
|
### Preload
|
@@ -190,7 +188,7 @@ You need to manage your secrets across different environments and apply them as
|
|
190
188
|
|
191
189
|
## đ Deploying
|
192
190
|
|
193
|
-
|
191
|
+
_Note: Requires dotenv >= 16.1.0_
|
194
192
|
|
195
193
|
Encrypt your `.env.vault` file.
|
196
194
|
|
@@ -213,7 +211,7 @@ heroku config:set DOTENV_KEY=dotenv://:key_1234âĻ@dotenv.org/vault/.env.vault?e
|
|
213
211
|
|
214
212
|
That's it! On deploy, your `.env.vault` file will be decrypted and its secrets injected as environment variables â just in time.
|
215
213
|
|
216
|
-
|
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._
|
217
215
|
|
218
216
|
<a href="https://github.com/dotenv-org/dotenv-vault#dotenv-vault-">Learn more at dotenv-vault: Deploying</a>
|
219
217
|
|
@@ -231,7 +229,7 @@ Regenerate your `.env.vault` file.
|
|
231
229
|
$ npx dotenv-vault build
|
232
230
|
```
|
233
231
|
|
234
|
-
|
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._
|
235
233
|
|
236
234
|
<a href="https://github.com/dotenv-org/dotenv-vault#-manage-multiple-environments">Learn more at dotenv-vault: Manage Multiple Environments</a>
|
237
235
|
|
@@ -239,32 +237,32 @@ $ npx dotenv-vault build
|
|
239
237
|
|
240
238
|
See [examples](https://github.com/dotenv-org/examples) of using dotenv with various frameworks, languages, and configurations.
|
241
239
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
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)
|
259
257
|
|
260
258
|
## đ Documentation
|
261
259
|
|
262
260
|
Dotenv exposes four functions:
|
263
261
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
262
|
+
- `config`
|
263
|
+
- `parse`
|
264
|
+
- `populate`
|
265
|
+
- `decrypt`
|
268
266
|
|
269
267
|
### Config
|
270
268
|
|
@@ -273,13 +271,13 @@ Dotenv exposes four functions:
|
|
273
271
|
and return an Object with a `parsed` key containing the loaded content or an `error` key if it failed.
|
274
272
|
|
275
273
|
```js
|
276
|
-
const result = dotenv.config()
|
274
|
+
const result = dotenv.config();
|
277
275
|
|
278
276
|
if (result.error) {
|
279
|
-
throw result.error
|
277
|
+
throw result.error;
|
280
278
|
}
|
281
279
|
|
282
|
-
console.log(result.parsed)
|
280
|
+
console.log(result.parsed);
|
283
281
|
```
|
284
282
|
|
285
283
|
You can additionally, pass options to `config`.
|
@@ -293,7 +291,7 @@ Default: `path.resolve(process.cwd(), '.env')`
|
|
293
291
|
Specify a custom path if your file containing environment variables is located elsewhere.
|
294
292
|
|
295
293
|
```js
|
296
|
-
require(
|
294
|
+
require("dotenv").config({ path: "/custom/path/to/.env" });
|
297
295
|
```
|
298
296
|
|
299
297
|
##### encoding
|
@@ -303,7 +301,7 @@ Default: `utf8`
|
|
303
301
|
Specify the encoding of your file containing environment variables.
|
304
302
|
|
305
303
|
```js
|
306
|
-
require(
|
304
|
+
require("dotenv").config({ encoding: "latin1" });
|
307
305
|
```
|
308
306
|
|
309
307
|
##### debug
|
@@ -313,7 +311,7 @@ Default: `false`
|
|
313
311
|
Turn on logging to help debug why certain keys or values are not being set as you expect.
|
314
312
|
|
315
313
|
```js
|
316
|
-
require(
|
314
|
+
require("dotenv").config({ debug: process.env.DEBUG });
|
317
315
|
```
|
318
316
|
|
319
317
|
##### override
|
@@ -323,7 +321,7 @@ Default: `false`
|
|
323
321
|
Override any environment variables that have already been set on your machine with values from your .env file.
|
324
322
|
|
325
323
|
```js
|
326
|
-
require(
|
324
|
+
require("dotenv").config({ override: true });
|
327
325
|
```
|
328
326
|
|
329
327
|
##### processEnv
|
@@ -333,11 +331,11 @@ Default: `process.env`
|
|
333
331
|
Specify an object to write your secrets to. Defaults to `process.env` environment variables.
|
334
332
|
|
335
333
|
```js
|
336
|
-
const myObject = {}
|
337
|
-
require(
|
334
|
+
const myObject = {};
|
335
|
+
require("dotenv").config({ processEnv: myObject });
|
338
336
|
|
339
|
-
console.log(myObject) // values from .env or .env.vault live here now.
|
340
|
-
console.log(process.env) // this was not changed or written to
|
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
|
341
339
|
```
|
342
340
|
|
343
341
|
##### DOTENV_KEY
|
@@ -347,7 +345,10 @@ Default: `process.env.DOTENV_KEY`
|
|
347
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.
|
348
346
|
|
349
347
|
```js
|
350
|
-
require(
|
348
|
+
require("dotenv").config({
|
349
|
+
DOTENV_KEY:
|
350
|
+
"dotenv://:key_1234âĻ@dotenv.org/vault/.env.vault?environment=production",
|
351
|
+
});
|
351
352
|
```
|
352
353
|
|
353
354
|
### Parse
|
@@ -357,10 +358,10 @@ variables is available to use. It accepts a String or Buffer and will return
|
|
357
358
|
an Object with the parsed keys and values.
|
358
359
|
|
359
360
|
```js
|
360
|
-
const dotenv = require(
|
361
|
-
const buf = Buffer.from(
|
362
|
-
const config = dotenv.parse(buf) // will return an object
|
363
|
-
console.log(typeof config, config) // object { BASIC : 'basic' }
|
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' }
|
364
365
|
```
|
365
366
|
|
366
367
|
#### Options
|
@@ -372,10 +373,10 @@ Default: `false`
|
|
372
373
|
Turn on logging to help debug why certain keys or values are not being set as you expect.
|
373
374
|
|
374
375
|
```js
|
375
|
-
const dotenv = require(
|
376
|
-
const buf = Buffer.from(
|
377
|
-
const opt = { debug: true }
|
378
|
-
const config = dotenv.parse(buf, opt)
|
376
|
+
const dotenv = require("dotenv");
|
377
|
+
const buf = Buffer.from("hello world");
|
378
|
+
const opt = { debug: true };
|
379
|
+
const config = dotenv.parse(buf, opt);
|
379
380
|
// expect a debug message because the buffer is not in KEY=VAL form
|
380
381
|
```
|
381
382
|
|
@@ -386,24 +387,24 @@ The engine which populates the contents of your .env file to `process.env` is av
|
|
386
387
|
For example, customizing the source:
|
387
388
|
|
388
389
|
```js
|
389
|
-
const dotenv = require(
|
390
|
-
const parsed = { HELLO:
|
390
|
+
const dotenv = require("dotenv");
|
391
|
+
const parsed = { HELLO: "world" };
|
391
392
|
|
392
|
-
dotenv.populate(process.env, parsed)
|
393
|
+
dotenv.populate(process.env, parsed);
|
393
394
|
|
394
|
-
console.log(process.env.HELLO) // world
|
395
|
+
console.log(process.env.HELLO); // world
|
395
396
|
```
|
396
397
|
|
397
398
|
For example, customizing the source AND target:
|
398
399
|
|
399
400
|
```js
|
400
|
-
const dotenv = require(
|
401
|
-
const parsed = { HELLO:
|
402
|
-
const target = { HELLO:
|
401
|
+
const dotenv = require("dotenv");
|
402
|
+
const parsed = { HELLO: "universe" };
|
403
|
+
const target = { HELLO: "world" }; // empty object
|
403
404
|
|
404
|
-
dotenv.populate(target, parsed, { override: true, debug: true })
|
405
|
+
dotenv.populate(target, parsed, { override: true, debug: true });
|
405
406
|
|
406
|
-
console.log(target) // { HELLO: 'universe' }
|
407
|
+
console.log(target); // { HELLO: 'universe' }
|
407
408
|
```
|
408
409
|
|
409
410
|
#### options
|
@@ -427,13 +428,15 @@ The engine which decrypts the ciphertext contents of your .env.vault file is ava
|
|
427
428
|
For example, decrypting a simple ciphertext:
|
428
429
|
|
429
430
|
```js
|
430
|
-
const dotenv = require(
|
431
|
-
const ciphertext =
|
432
|
-
|
431
|
+
const dotenv = require("dotenv");
|
432
|
+
const ciphertext =
|
433
|
+
"s7NYXa809k/bVSPwIAmJhPJmEGTtU0hG58hOZy7I0ix6y5HP8LsHBsZCYC/gw5DDFy5DgOcyd18R";
|
434
|
+
const decryptionKey =
|
435
|
+
"ddcaa26504cd70a6fef9801901c3981538563a1767c297cb8416e8a38c62fe00";
|
433
436
|
|
434
|
-
const decrypted = dotenv.decrypt(ciphertext, decryptionKey)
|
437
|
+
const decrypted = dotenv.decrypt(ciphertext, decryptionKey);
|
435
438
|
|
436
|
-
console.log(decrypted) // # development@v6\nALPHA="zeta"
|
439
|
+
console.log(decrypted); // # development@v6\nALPHA="zeta"
|
437
440
|
```
|
438
441
|
|
439
442
|
## â FAQ
|
@@ -445,7 +448,7 @@ Most likely your `.env` file is not in the correct place. [See this stack overfl
|
|
445
448
|
Turn on debug mode and try again..
|
446
449
|
|
447
450
|
```js
|
448
|
-
require(
|
451
|
+
require("dotenv").config({ debug: true });
|
449
452
|
```
|
450
453
|
|
451
454
|
You will receive a helpful error outputted to your console.
|
@@ -494,7 +497,7 @@ By default, we will never modify any environment variables that have already bee
|
|
494
497
|
If instead, you want to override `process.env` use the `override` option.
|
495
498
|
|
496
499
|
```javascript
|
497
|
-
require(
|
500
|
+
require("dotenv").config({ override: true });
|
498
501
|
```
|
499
502
|
|
500
503
|
### How come my environment variables are not showing up for React?
|
@@ -510,10 +513,10 @@ If you are using other frameworks (e.g. Next.js, Gatsby...), you need to consult
|
|
510
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:
|
511
514
|
|
512
515
|
```js
|
513
|
-
const dotenv = require(
|
514
|
-
const variableExpansion = require(
|
515
|
-
const myEnv = dotenv.config()
|
516
|
-
variableExpansion(myEnv)
|
516
|
+
const dotenv = require("dotenv");
|
517
|
+
const variableExpansion = require("dotenv-expand");
|
518
|
+
const myEnv = dotenv.config();
|
519
|
+
variableExpansion(myEnv);
|
517
520
|
```
|
518
521
|
|
519
522
|
### How do I use dotenv with `import`?
|
@@ -522,8 +525,8 @@ Simply..
|
|
522
525
|
|
523
526
|
```javascript
|
524
527
|
// index.mjs (ESM)
|
525
|
-
import
|
526
|
-
import express from
|
528
|
+
import "dotenv/config"; // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
|
529
|
+
import express from "express";
|
527
530
|
```
|
528
531
|
|
529
532
|
A little background..
|
@@ -535,19 +538,22 @@ A little background..
|
|
535
538
|
What does this mean in plain language? It means you would think the following would work but it won't.
|
536
539
|
|
537
540
|
`errorReporter.mjs`:
|
541
|
+
|
538
542
|
```js
|
539
|
-
import { Client } from
|
543
|
+
import { Client } from "best-error-reporting-service";
|
540
544
|
|
541
|
-
export default new Client(process.env.API_KEY)
|
545
|
+
export default new Client(process.env.API_KEY);
|
542
546
|
```
|
547
|
+
|
543
548
|
`index.mjs`:
|
549
|
+
|
544
550
|
```js
|
545
551
|
// Note: this is INCORRECT and will not work
|
546
|
-
import * as dotenv from
|
547
|
-
dotenv.config()
|
552
|
+
import * as dotenv from "dotenv";
|
553
|
+
dotenv.config();
|
548
554
|
|
549
|
-
import errorReporter from
|
550
|
-
errorReporter.report(new Error(
|
555
|
+
import errorReporter from "./errorReporter.mjs";
|
556
|
+
errorReporter.report(new Error("documented example"));
|
551
557
|
```
|
552
558
|
|
553
559
|
`process.env.API_KEY` will be blank.
|
@@ -555,10 +561,10 @@ errorReporter.report(new Error('documented example'))
|
|
555
561
|
Instead, `index.mjs` should be written as..
|
556
562
|
|
557
563
|
```js
|
558
|
-
import
|
564
|
+
import "dotenv/config";
|
559
565
|
|
560
|
-
import errorReporter from
|
561
|
-
errorReporter.report(new Error(
|
566
|
+
import errorReporter from "./errorReporter.mjs";
|
567
|
+
errorReporter.report(new Error("documented example"));
|
562
568
|
```
|
563
569
|
|
564
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).
|
@@ -579,28 +585,28 @@ npm install node-polyfill-webpack-plugin
|
|
579
585
|
Configure your `webpack.config.js` to something like the following.
|
580
586
|
|
581
587
|
```js
|
582
|
-
require(
|
588
|
+
require("dotenv").config();
|
583
589
|
|
584
|
-
const path = require(
|
585
|
-
const webpack = require(
|
590
|
+
const path = require("path");
|
591
|
+
const webpack = require("webpack");
|
586
592
|
|
587
|
-
const NodePolyfillPlugin = require(
|
593
|
+
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
|
588
594
|
|
589
595
|
module.exports = {
|
590
|
-
mode:
|
591
|
-
entry:
|
596
|
+
mode: "development",
|
597
|
+
entry: "./src/index.ts",
|
592
598
|
output: {
|
593
|
-
filename:
|
594
|
-
path: path.resolve(__dirname,
|
599
|
+
filename: "bundle.js",
|
600
|
+
path: path.resolve(__dirname, "dist"),
|
595
601
|
},
|
596
602
|
plugins: [
|
597
603
|
new NodePolyfillPlugin(),
|
598
604
|
new webpack.DefinePlugin({
|
599
|
-
|
600
|
-
HELLO: JSON.stringify(process.env.HELLO)
|
601
|
-
}
|
605
|
+
"process.env": {
|
606
|
+
HELLO: JSON.stringify(process.env.HELLO),
|
607
|
+
},
|
602
608
|
}),
|
603
|
-
]
|
609
|
+
],
|
604
610
|
};
|
605
611
|
```
|
606
612
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "wrap-env",
|
3
|
-
"version": "16.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",
|
package/README-es.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
This package is an wrap of `dotenv`
|