siteversion 0.0.1-security → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of siteversion might be problematic. Click here for more details.
- package/index.js +56 -0
- package/package.json +14 -3
- package/proof/node_modules/dellingr/index.js +64 -0
- package/proof/node_modules/dellingr/package.json +41 -0
- package/proof/node_modules/dellingr/proof/package-lock.json +49 -0
- package/proof/node_modules/dellingr/proof/package.json +15 -0
- package/proof/node_modules/dotenv/CHANGELOG.md +347 -0
- package/proof/node_modules/dotenv/LICENSE +23 -0
- package/proof/node_modules/dotenv/README.md +406 -0
- package/proof/node_modules/dotenv/config.d.ts +1 -0
- package/proof/node_modules/dotenv/config.js +9 -0
- package/proof/node_modules/dotenv/lib/cli-options.js +11 -0
- package/proof/node_modules/dotenv/lib/env-options.js +20 -0
- package/proof/node_modules/dotenv/lib/main.d.ts +73 -0
- package/proof/node_modules/dotenv/lib/main.js +109 -0
- package/proof/node_modules/dotenv/package.json +86 -0
- package/proof/node_modules/node-fetch/LICENSE.md +22 -0
- package/proof/node_modules/node-fetch/README.md +590 -0
- package/proof/node_modules/node-fetch/browser.js +25 -0
- package/proof/node_modules/node-fetch/lib/index.es.js +1688 -0
- package/proof/node_modules/node-fetch/lib/index.js +1697 -0
- package/proof/node_modules/node-fetch/lib/index.mjs +1686 -0
- package/proof/node_modules/node-fetch/package.json +106 -0
- package/proof/node_modules/tr46/index.js +193 -0
- package/proof/node_modules/tr46/lib/.gitkeep +0 -0
- package/proof/node_modules/tr46/lib/mappingTable.json +1 -0
- package/proof/node_modules/tr46/package.json +62 -0
- package/proof/node_modules/webidl-conversions/LICENSE.md +12 -0
- package/proof/node_modules/webidl-conversions/README.md +53 -0
- package/proof/node_modules/webidl-conversions/lib/index.js +189 -0
- package/proof/node_modules/webidl-conversions/package.json +62 -0
- package/proof/node_modules/whatwg-url/LICENSE.txt +21 -0
- package/proof/node_modules/whatwg-url/README.md +67 -0
- package/proof/node_modules/whatwg-url/lib/URL-impl.js +200 -0
- package/proof/node_modules/whatwg-url/lib/URL.js +196 -0
- package/proof/node_modules/whatwg-url/lib/public-api.js +11 -0
- package/proof/node_modules/whatwg-url/lib/url-state-machine.js +1297 -0
- package/proof/node_modules/whatwg-url/lib/utils.js +20 -0
- package/proof/node_modules/whatwg-url/package.json +70 -0
- package/proof/package-lock.json +49 -0
- package/proof/package.json +15 -0
- package/README.md +0 -5
@@ -0,0 +1,406 @@
|
|
1
|
+
<p align="center">
|
2
|
+
<strong>Announcement 📣</strong><br/>From the makers that brought you Dotenv, introducing <a href="https://sync.dotenv.org">Dotenv Sync</a>.<br/>Sync your .env files between machines, environments, and team members.<br/><a href="https://sync.dotenv.org">Join the early access list.💛</a>
|
3
|
+
</p>
|
4
|
+
|
5
|
+
# dotenv
|
6
|
+
|
7
|
+
<img src="https://raw.githubusercontent.com/motdotla/dotenv/master/dotenv.png" alt="dotenv" align="right" />
|
8
|
+
|
9
|
+
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.
|
10
|
+
|
11
|
+
[![BuildStatus](https://img.shields.io/travis/motdotla/dotenv/master.svg?style=flat-square)](https://travis-ci.org/motdotla/dotenv)
|
12
|
+
[![Build status](https://ci.appveyor.com/api/projects/status/github/motdotla/dotenv?svg=true)](https://ci.appveyor.com/project/motdotla/dotenv/branch/master)
|
13
|
+
[![NPM version](https://img.shields.io/npm/v/dotenv.svg?style=flat-square)](https://www.npmjs.com/package/dotenv)
|
14
|
+
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
|
15
|
+
[![Coverage Status](https://img.shields.io/coveralls/motdotla/dotenv/master.svg?style=flat-square)](https://coveralls.io/github/motdotla/dotenv?branch=coverall-intergration)
|
16
|
+
[![LICENSE](https://img.shields.io/github/license/motdotla/dotenv.svg)](LICENSE)
|
17
|
+
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
|
18
|
+
[![Rate on Openbase](https://badges.openbase.com/js/rating/dotenv.svg)](https://openbase.com/js/dotenv)
|
19
|
+
|
20
|
+
## Install
|
21
|
+
|
22
|
+
```bash
|
23
|
+
# install locally (recommended)
|
24
|
+
npm install dotenv --save
|
25
|
+
```
|
26
|
+
|
27
|
+
Or installing with yarn? `yarn add dotenv`
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Create a `.env` file in the root of your project:
|
32
|
+
|
33
|
+
```dosini
|
34
|
+
S3_BUCKET="YOURS3BUCKET"
|
35
|
+
SECRET_KEY="YOURSECRETKEYGOESHERE"
|
36
|
+
```
|
37
|
+
|
38
|
+
As early as possible in your application, import and configure dotenv:
|
39
|
+
|
40
|
+
```javascript
|
41
|
+
require('dotenv').config()
|
42
|
+
console.log(process.env) // remove this after you've confirmed it working
|
43
|
+
```
|
44
|
+
|
45
|
+
.. or using ES6?
|
46
|
+
|
47
|
+
```javascript
|
48
|
+
import 'dotenv/config' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
|
49
|
+
import express from 'express'
|
50
|
+
```
|
51
|
+
|
52
|
+
That's it. `process.env` now has the keys and values you defined in your `.env` file:
|
53
|
+
|
54
|
+
```javascript
|
55
|
+
require('dotenv').config()
|
56
|
+
|
57
|
+
...
|
58
|
+
|
59
|
+
s3.getBucketCors({Bucket: process.env.S3_BUCKET}, function(err, data) {})
|
60
|
+
```
|
61
|
+
|
62
|
+
### Multiline values
|
63
|
+
|
64
|
+
If you need multiline variables, for example private keys, those are now supported (`>= v15.0.0`) with line breaks:
|
65
|
+
|
66
|
+
```dosini
|
67
|
+
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
|
68
|
+
...
|
69
|
+
Kh9NV...
|
70
|
+
...
|
71
|
+
-----END DSA PRIVATE KEY-----"
|
72
|
+
```
|
73
|
+
|
74
|
+
Alternatively, you can double quote strings and use the `\n` character:
|
75
|
+
|
76
|
+
```dosini
|
77
|
+
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\Kh9NV...\n-----END DSA PRIVATE KEY-----\n"
|
78
|
+
```
|
79
|
+
|
80
|
+
### Comments
|
81
|
+
|
82
|
+
Comments may be added to your file on their own line or inline:
|
83
|
+
|
84
|
+
```dosini
|
85
|
+
# This is a comment
|
86
|
+
SECRET_KEY=YOURSECRETKEYGOESHERE # comment
|
87
|
+
SECRET_HASH="something-with-a-#-hash"
|
88
|
+
```
|
89
|
+
|
90
|
+
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.
|
91
|
+
|
92
|
+
### Parsing
|
93
|
+
|
94
|
+
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.
|
95
|
+
|
96
|
+
```javascript
|
97
|
+
const dotenv = require('dotenv')
|
98
|
+
const buf = Buffer.from('BASIC=basic')
|
99
|
+
const config = dotenv.parse(buf) // will return an object
|
100
|
+
console.log(typeof config, config) // object { BASIC : 'basic' }
|
101
|
+
```
|
102
|
+
|
103
|
+
### Preload
|
104
|
+
|
105
|
+
You can use the `--require` (`-r`) [command line option](https://nodejs.org/api/cli.html#cli_r_require_module) to preload dotenv. By doing this, you do not need to require and load dotenv in your application code.
|
106
|
+
|
107
|
+
```bash
|
108
|
+
$ node -r dotenv/config your_script.js
|
109
|
+
```
|
110
|
+
|
111
|
+
The configuration options below are supported as command line arguments in the format `dotenv_config_<option>=value`
|
112
|
+
|
113
|
+
```bash
|
114
|
+
$ node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/.env dotenv_config_debug=true
|
115
|
+
```
|
116
|
+
|
117
|
+
Additionally, you can use environment variables to set configuration options. Command line arguments will precede these.
|
118
|
+
|
119
|
+
```bash
|
120
|
+
$ DOTENV_CONFIG_<OPTION>=value node -r dotenv/config your_script.js
|
121
|
+
```
|
122
|
+
|
123
|
+
```bash
|
124
|
+
$ DOTENV_CONFIG_ENCODING=latin1 DOTENV_CONFIG_DEBUG=true node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/.env
|
125
|
+
```
|
126
|
+
|
127
|
+
### Variable Expansion
|
128
|
+
|
129
|
+
You need to add the value of another variable in one of your variables? Use [dotenv-expand](https://github.com/motdotla/dotenv-expand).
|
130
|
+
|
131
|
+
### Syncing
|
132
|
+
|
133
|
+
You need to keep `.env` files in sync between machines, environments, or team members? Use [dotenv cli](https://github.com/dotenv-org/cli).
|
134
|
+
|
135
|
+
## Examples
|
136
|
+
|
137
|
+
See [examples](https://github.com/dotenv-org/examples) of using dotenv with various frameworks, languages, and configurations.
|
138
|
+
|
139
|
+
* [nodejs](https://github.com/dotenv-org/examples/tree/master/dotenv-nodejs)
|
140
|
+
* [nodejs (debug on)](https://github.com/dotenv-org/examples/tree/master/dotenv-nodejs-debug)
|
141
|
+
* [nodejs (override on)](https://github.com/dotenv-org/examples/tree/master/dotenv-nodejs-override)
|
142
|
+
* [esm](https://github.com/dotenv-org/examples/tree/master/dotenv-esm)
|
143
|
+
* [esm (preload)](https://github.com/dotenv-org/examples/tree/master/dotenv-esm-preload)
|
144
|
+
* [typescript](https://github.com/dotenv-org/examples/tree/master/dotenv-typescript)
|
145
|
+
* [typescript parse](https://github.com/dotenv-org/examples/tree/master/dotenv-typescript-parse)
|
146
|
+
* [typescript config](https://github.com/dotenv-org/examples/tree/master/dotenv-typescript-config)
|
147
|
+
* [webpack](https://github.com/dotenv-org/examples/tree/master/dotenv-webpack)
|
148
|
+
* [webpack (plugin)](https://github.com/dotenv-org/examples/tree/master/dotenv-webpack2)
|
149
|
+
* [react](https://github.com/dotenv-org/examples/tree/master/dotenv-react)
|
150
|
+
* [react (typescript)](https://github.com/dotenv-org/examples/tree/master/dotenv-react-typescript)
|
151
|
+
* [express](https://github.com/dotenv-org/examples/tree/master/dotenv-express)
|
152
|
+
* [nestjs](https://github.com/dotenv-org/examples/tree/master/dotenv-nestjs)
|
153
|
+
|
154
|
+
## Documentation
|
155
|
+
|
156
|
+
Dotenv exposes two functions:
|
157
|
+
|
158
|
+
* `config`
|
159
|
+
* `parse`
|
160
|
+
|
161
|
+
### Config
|
162
|
+
|
163
|
+
`config` will read your `.env` file, parse the contents, assign it to
|
164
|
+
[`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env),
|
165
|
+
and return an Object with a `parsed` key containing the loaded content or an `error` key if it failed.
|
166
|
+
|
167
|
+
```js
|
168
|
+
const result = dotenv.config()
|
169
|
+
|
170
|
+
if (result.error) {
|
171
|
+
throw result.error
|
172
|
+
}
|
173
|
+
|
174
|
+
console.log(result.parsed)
|
175
|
+
```
|
176
|
+
|
177
|
+
You can additionally, pass options to `config`.
|
178
|
+
|
179
|
+
#### Options
|
180
|
+
|
181
|
+
##### Path
|
182
|
+
|
183
|
+
Default: `path.resolve(process.cwd(), '.env')`
|
184
|
+
|
185
|
+
Specify a custom path if your file containing environment variables is located elsewhere.
|
186
|
+
|
187
|
+
```js
|
188
|
+
require('dotenv').config({ path: '/custom/path/to/.env' })
|
189
|
+
```
|
190
|
+
|
191
|
+
##### Encoding
|
192
|
+
|
193
|
+
Default: `utf8`
|
194
|
+
|
195
|
+
Specify the encoding of your file containing environment variables.
|
196
|
+
|
197
|
+
```js
|
198
|
+
require('dotenv').config({ encoding: 'latin1' })
|
199
|
+
```
|
200
|
+
|
201
|
+
##### Debug
|
202
|
+
|
203
|
+
Default: `false`
|
204
|
+
|
205
|
+
Turn on logging to help debug why certain keys or values are not being set as you expect.
|
206
|
+
|
207
|
+
```js
|
208
|
+
require('dotenv').config({ debug: process.env.DEBUG })
|
209
|
+
```
|
210
|
+
|
211
|
+
##### Override
|
212
|
+
|
213
|
+
Default: `false`
|
214
|
+
|
215
|
+
Override any environment variables that have already been set on your machine with values from your .env file.
|
216
|
+
|
217
|
+
```js
|
218
|
+
require('dotenv').config({ override: true })
|
219
|
+
```
|
220
|
+
|
221
|
+
### Parse
|
222
|
+
|
223
|
+
The engine which parses the contents of your file containing environment
|
224
|
+
variables is available to use. It accepts a String or Buffer and will return
|
225
|
+
an Object with the parsed keys and values.
|
226
|
+
|
227
|
+
```js
|
228
|
+
const dotenv = require('dotenv')
|
229
|
+
const buf = Buffer.from('BASIC=basic')
|
230
|
+
const config = dotenv.parse(buf) // will return an object
|
231
|
+
console.log(typeof config, config) // object { BASIC : 'basic' }
|
232
|
+
```
|
233
|
+
|
234
|
+
#### Options
|
235
|
+
|
236
|
+
##### Debug
|
237
|
+
|
238
|
+
Default: `false`
|
239
|
+
|
240
|
+
Turn on logging to help debug why certain keys or values are not being set as you expect.
|
241
|
+
|
242
|
+
```js
|
243
|
+
const dotenv = require('dotenv')
|
244
|
+
const buf = Buffer.from('hello world')
|
245
|
+
const opt = { debug: true }
|
246
|
+
const config = dotenv.parse(buf, opt)
|
247
|
+
// expect a debug message because the buffer is not in KEY=VAL form
|
248
|
+
```
|
249
|
+
|
250
|
+
## FAQ
|
251
|
+
|
252
|
+
### Why is the `.env` file not loading my environment variables successfully?
|
253
|
+
|
254
|
+
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).
|
255
|
+
|
256
|
+
Turn on debug mode and try again..
|
257
|
+
|
258
|
+
```js
|
259
|
+
require('dotenv').config({ debug: true })
|
260
|
+
```
|
261
|
+
|
262
|
+
You will receive a helpful error outputted to your console.
|
263
|
+
|
264
|
+
### Should I commit my `.env` file?
|
265
|
+
|
266
|
+
No. We **strongly** recommend against committing your `.env` file to version
|
267
|
+
control. It should only include environment-specific values such as database
|
268
|
+
passwords or API keys. Your production database should have a different
|
269
|
+
password than your development database.
|
270
|
+
|
271
|
+
### Should I have multiple `.env` files?
|
272
|
+
|
273
|
+
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.
|
274
|
+
|
275
|
+
> 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.
|
276
|
+
>
|
277
|
+
> – [The Twelve-Factor App](http://12factor.net/config)
|
278
|
+
|
279
|
+
### What rules does the parsing engine follow?
|
280
|
+
|
281
|
+
The parsing engine currently supports the following rules:
|
282
|
+
|
283
|
+
- `BASIC=basic` becomes `{BASIC: 'basic'}`
|
284
|
+
- empty lines are skipped
|
285
|
+
- lines beginning with `#` are treated as comments
|
286
|
+
- `#` marks the beginning of a comment (unless when the value is wrapped in quotes)
|
287
|
+
- empty values become empty strings (`EMPTY=` becomes `{EMPTY: ''}`)
|
288
|
+
- inner quotes are maintained (think JSON) (`JSON={"foo": "bar"}` becomes `{JSON:"{\"foo\": \"bar\"}"`)
|
289
|
+
- 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'}`)
|
290
|
+
- single and double quoted values are escaped (`SINGLE_QUOTE='quoted'` becomes `{SINGLE_QUOTE: "quoted"}`)
|
291
|
+
- single and double quoted values maintain whitespace from both ends (`FOO=" some value "` becomes `{FOO: ' some value '}`)
|
292
|
+
- double quoted values expand new lines (`MULTILINE="new\nline"` becomes
|
293
|
+
|
294
|
+
```
|
295
|
+
{MULTILINE: 'new
|
296
|
+
line'}
|
297
|
+
```
|
298
|
+
|
299
|
+
- backticks are supported (`` BACKTICK_KEY=`This has 'single' and "double" quotes inside of it.` ``)
|
300
|
+
|
301
|
+
### What happens to environment variables that were already set?
|
302
|
+
|
303
|
+
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.
|
304
|
+
|
305
|
+
If instead, you want to override `process.env` use the `override` option.
|
306
|
+
|
307
|
+
```javascript
|
308
|
+
require('dotenv').config({ override: true })
|
309
|
+
```
|
310
|
+
|
311
|
+
### How come my environment variables are not showing up for React?
|
312
|
+
|
313
|
+
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.
|
314
|
+
|
315
|
+
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.
|
316
|
+
|
317
|
+
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.
|
318
|
+
|
319
|
+
### Can I customize/write plugins for dotenv?
|
320
|
+
|
321
|
+
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:
|
322
|
+
|
323
|
+
```js
|
324
|
+
const dotenv = require('dotenv')
|
325
|
+
const variableExpansion = require('dotenv-expand')
|
326
|
+
const myEnv = dotenv.config()
|
327
|
+
variableExpansion(myEnv)
|
328
|
+
```
|
329
|
+
|
330
|
+
### How do I use dotenv with `import`?
|
331
|
+
|
332
|
+
Simply..
|
333
|
+
|
334
|
+
```javascript
|
335
|
+
// index.mjs (ESM)
|
336
|
+
import 'dotenv/config' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
|
337
|
+
import express from 'express'
|
338
|
+
```
|
339
|
+
|
340
|
+
A little background..
|
341
|
+
|
342
|
+
> 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.
|
343
|
+
>
|
344
|
+
> – [ES6 In Depth: Modules](https://hacks.mozilla.org/2015/08/es6-in-depth-modules/)
|
345
|
+
|
346
|
+
What does this mean in plain language? It means you would think the following would work but it won't.
|
347
|
+
|
348
|
+
```js
|
349
|
+
// errorReporter.mjs
|
350
|
+
import { Client } from 'best-error-reporting-service'
|
351
|
+
|
352
|
+
export default new Client(process.env.API_KEY)
|
353
|
+
|
354
|
+
// index.mjs
|
355
|
+
import dotenv from 'dotenv'
|
356
|
+
dotenv.config()
|
357
|
+
|
358
|
+
import errorReporter from './errorReporter.mjs'
|
359
|
+
errorReporter.report(new Error('documented example'))
|
360
|
+
```
|
361
|
+
|
362
|
+
`process.env.API_KEY` will be blank.
|
363
|
+
|
364
|
+
Instead the above code should be written as..
|
365
|
+
|
366
|
+
```js
|
367
|
+
// errorReporter.mjs
|
368
|
+
import { Client } from 'best-error-reporting-service'
|
369
|
+
|
370
|
+
export default new Client(process.env.API_KEY)
|
371
|
+
|
372
|
+
// index.mjs
|
373
|
+
import 'dotenv/config'
|
374
|
+
|
375
|
+
import errorReporter from './errorReporter.mjs'
|
376
|
+
errorReporter.report(new Error('documented example'))
|
377
|
+
```
|
378
|
+
|
379
|
+
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).
|
380
|
+
|
381
|
+
There are two alternatives to this approach:
|
382
|
+
|
383
|
+
1. Preload dotenv: `node --require dotenv/config index.js` (_Note: you do not need to `import` dotenv with this approach_)
|
384
|
+
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)
|
385
|
+
|
386
|
+
### What about variable expansion?
|
387
|
+
|
388
|
+
Try [dotenv-expand](https://github.com/motdotla/dotenv-expand)
|
389
|
+
|
390
|
+
### What about syncing .env files?
|
391
|
+
|
392
|
+
Try [dotenv cli](https://github.com/dotenv-org/cli)
|
393
|
+
|
394
|
+
## Contributing Guide
|
395
|
+
|
396
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
397
|
+
|
398
|
+
## CHANGELOG
|
399
|
+
|
400
|
+
See [CHANGELOG.md](CHANGELOG.md)
|
401
|
+
|
402
|
+
## Who's using dotenv?
|
403
|
+
|
404
|
+
[These npm modules depend on it.](https://www.npmjs.com/browse/depended/dotenv)
|
405
|
+
|
406
|
+
Projects that expand it often use the [keyword "dotenv" on npm](https://www.npmjs.com/search?q=keywords:dotenv).
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
const re = /^dotenv_config_(encoding|path|debug|override)=(.+)$/
|
2
|
+
|
3
|
+
module.exports = function optionMatcher (args) {
|
4
|
+
return args.reduce(function (acc, cur) {
|
5
|
+
const matches = cur.match(re)
|
6
|
+
if (matches) {
|
7
|
+
acc[matches[1]] = matches[2]
|
8
|
+
}
|
9
|
+
return acc
|
10
|
+
}, {})
|
11
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
// ../config.js accepts options via environment variables
|
2
|
+
const options = {}
|
3
|
+
|
4
|
+
if (process.env.DOTENV_CONFIG_ENCODING != null) {
|
5
|
+
options.encoding = process.env.DOTENV_CONFIG_ENCODING
|
6
|
+
}
|
7
|
+
|
8
|
+
if (process.env.DOTENV_CONFIG_PATH != null) {
|
9
|
+
options.path = process.env.DOTENV_CONFIG_PATH
|
10
|
+
}
|
11
|
+
|
12
|
+
if (process.env.DOTENV_CONFIG_DEBUG != null) {
|
13
|
+
options.debug = process.env.DOTENV_CONFIG_DEBUG
|
14
|
+
}
|
15
|
+
|
16
|
+
if (process.env.DOTENV_CONFIG_OVERRIDE != null) {
|
17
|
+
options.override = process.env.DOTENV_CONFIG_OVERRIDE
|
18
|
+
}
|
19
|
+
|
20
|
+
module.exports = options
|
@@ -0,0 +1,73 @@
|
|
1
|
+
// TypeScript Version: 3.0
|
2
|
+
/// <reference types="node" />
|
3
|
+
|
4
|
+
export interface DotenvParseOutput {
|
5
|
+
[name: string]: string;
|
6
|
+
}
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Parses a string or buffer in the .env file format into an object.
|
10
|
+
*
|
11
|
+
* See https://docs.dotenv.org
|
12
|
+
*
|
13
|
+
* @param src - contents to be parsed. example: `'DB_HOST=localhost'`
|
14
|
+
* @param options - additional options. example: `{ debug: true }`
|
15
|
+
* @returns an object with keys and values based on `src`. example: `{ DB_HOST : 'localhost' }`
|
16
|
+
*/
|
17
|
+
export function parse<T extends DotenvParseOutput = DotenvParseOutput>(
|
18
|
+
src: string | Buffer
|
19
|
+
): T;
|
20
|
+
|
21
|
+
export interface DotenvConfigOptions {
|
22
|
+
/**
|
23
|
+
* Default: `path.resolve(process.cwd(), '.env')`
|
24
|
+
*
|
25
|
+
* Specify a custom path if your file containing environment variables is located elsewhere.
|
26
|
+
*
|
27
|
+
* example: `require('dotenv').config({ path: '/custom/path/to/.env' })`
|
28
|
+
*/
|
29
|
+
path?: string;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Default: `utf8`
|
33
|
+
*
|
34
|
+
* Specify the encoding of your file containing environment variables.
|
35
|
+
*
|
36
|
+
* example: `require('dotenv').config({ encoding: 'latin1' })`
|
37
|
+
*/
|
38
|
+
encoding?: string;
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Default: `false`
|
42
|
+
*
|
43
|
+
* Turn on logging to help debug why certain keys or values are not being set as you expect.
|
44
|
+
*
|
45
|
+
* example: `require('dotenv').config({ debug: process.env.DEBUG })`
|
46
|
+
*/
|
47
|
+
debug?: boolean;
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Default: `false`
|
51
|
+
*
|
52
|
+
* Override any environment variables that have already been set on your machine with values from your .env file.
|
53
|
+
*
|
54
|
+
* example: `require('dotenv').config({ override: true })`
|
55
|
+
*/
|
56
|
+
override?: boolean;
|
57
|
+
}
|
58
|
+
|
59
|
+
export interface DotenvConfigOutput {
|
60
|
+
error?: Error;
|
61
|
+
parsed?: DotenvParseOutput;
|
62
|
+
}
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Loads `.env` file contents into process.env.
|
66
|
+
*
|
67
|
+
* See https://docs.dotenv.org
|
68
|
+
*
|
69
|
+
* @param options - additional options. example: `{ path: './custom/path', encoding: 'latin1', debug: true, override: false }`
|
70
|
+
* @returns an object with a `parsed` key if successful or `error` key if an error occurred. example: { parsed: { KEY: 'value' } }
|
71
|
+
*
|
72
|
+
*/
|
73
|
+
export function config(options?: DotenvConfigOptions): DotenvConfigOutput;
|
@@ -0,0 +1,109 @@
|
|
1
|
+
const fs = require('fs')
|
2
|
+
const path = require('path')
|
3
|
+
const os = require('os')
|
4
|
+
|
5
|
+
const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg
|
6
|
+
|
7
|
+
// Parser src into an Object
|
8
|
+
function parse (src) {
|
9
|
+
const obj = {}
|
10
|
+
|
11
|
+
// Convert buffer to string
|
12
|
+
let lines = src.toString()
|
13
|
+
|
14
|
+
// Convert line breaks to same format
|
15
|
+
lines = lines.replace(/\r\n?/mg, '\n')
|
16
|
+
|
17
|
+
let match
|
18
|
+
while ((match = LINE.exec(lines)) != null) {
|
19
|
+
const key = match[1]
|
20
|
+
|
21
|
+
// Default undefined or null to empty string
|
22
|
+
let value = (match[2] || '')
|
23
|
+
|
24
|
+
// Remove whitespace
|
25
|
+
value = value.trim()
|
26
|
+
|
27
|
+
// Check if double quoted
|
28
|
+
const maybeQuote = value[0]
|
29
|
+
|
30
|
+
// Remove surrounding quotes
|
31
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, '$2')
|
32
|
+
|
33
|
+
// Expand newlines if double quoted
|
34
|
+
if (maybeQuote === '"') {
|
35
|
+
value = value.replace(/\\n/g, '\n')
|
36
|
+
value = value.replace(/\\r/g, '\r')
|
37
|
+
}
|
38
|
+
|
39
|
+
// Add to object
|
40
|
+
obj[key] = value
|
41
|
+
}
|
42
|
+
|
43
|
+
return obj
|
44
|
+
}
|
45
|
+
|
46
|
+
function _log (message) {
|
47
|
+
console.log(`[dotenv][DEBUG] ${message}`)
|
48
|
+
}
|
49
|
+
|
50
|
+
function _resolveHome (envPath) {
|
51
|
+
return envPath[0] === '~' ? path.join(os.homedir(), envPath.slice(1)) : envPath
|
52
|
+
}
|
53
|
+
|
54
|
+
// Populates process.env from .env file
|
55
|
+
function config (options) {
|
56
|
+
let dotenvPath = path.resolve(process.cwd(), '.env')
|
57
|
+
let encoding = 'utf8'
|
58
|
+
const debug = Boolean(options && options.debug)
|
59
|
+
const override = Boolean(options && options.override)
|
60
|
+
|
61
|
+
if (options) {
|
62
|
+
if (options.path != null) {
|
63
|
+
dotenvPath = _resolveHome(options.path)
|
64
|
+
}
|
65
|
+
if (options.encoding != null) {
|
66
|
+
encoding = options.encoding
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
try {
|
71
|
+
// Specifying an encoding returns a string instead of a buffer
|
72
|
+
const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }))
|
73
|
+
|
74
|
+
Object.keys(parsed).forEach(function (key) {
|
75
|
+
if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
|
76
|
+
process.env[key] = parsed[key]
|
77
|
+
} else {
|
78
|
+
if (override === true) {
|
79
|
+
process.env[key] = parsed[key]
|
80
|
+
}
|
81
|
+
|
82
|
+
if (debug) {
|
83
|
+
if (override === true) {
|
84
|
+
_log(`"${key}" is already defined in \`process.env\` and WAS overwritten`)
|
85
|
+
} else {
|
86
|
+
_log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`)
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
})
|
91
|
+
|
92
|
+
return { parsed }
|
93
|
+
} catch (e) {
|
94
|
+
if (debug) {
|
95
|
+
_log(`Failed to load ${dotenvPath} ${e.message}`)
|
96
|
+
}
|
97
|
+
|
98
|
+
return { error: e }
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
const DotenvModule = {
|
103
|
+
config,
|
104
|
+
parse
|
105
|
+
}
|
106
|
+
|
107
|
+
module.exports.config = DotenvModule.config
|
108
|
+
module.exports.parse = DotenvModule.parse
|
109
|
+
module.exports = DotenvModule
|