Socket
Socket
Sign inDemoInstall

dotenv

Package Overview
Dependencies
Maintainers
4
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenv - npm Package Compare versions

Comparing version 6.2.0 to 7.0.0

13

CHANGELOG.md

@@ -7,2 +7,12 @@ # Change Log

## [7.0.0] - 2019-03-12
### Fixed
- Fix removing unbalanced quotes ([#376](https://github.com/motdotla/dotenv/pull/376))
### Removed
- Removed `load` alias for `config` for consistency throughout code and documentation.
## [6.2.0] - 2018-12-03

@@ -108,3 +118,4 @@

[Unreleased]: https://github.com/motdotla/dotenv/compare/v6.2.0...HEAD
[Unreleased]: https://github.com/motdotla/dotenv/compare/v7.0.0...HEAD
[7.0.0]: https://github.com/motdotla/dotenv/compare/v6.2.0...v7.0.0
[6.2.0]: https://github.com/motdotla/dotenv/compare/v6.1.0...v6.2.0

@@ -111,0 +122,0 @@ [6.1.0]: https://github.com/motdotla/dotenv/compare/v6.0.0...v6.1.0

6

lib/env-options.js

@@ -6,11 +6,11 @@ /* @flow */

if (process.env.DOTENV_CONFIG_ENCODING) {
if (process.env.DOTENV_CONFIG_ENCODING != null) {
options.encoding = process.env.DOTENV_CONFIG_ENCODING
}
if (process.env.DOTENV_CONFIG_PATH) {
if (process.env.DOTENV_CONFIG_PATH != null) {
options.path = process.env.DOTENV_CONFIG_PATH
}
if (process.env.DOTENV_CONFIG_DEBUG) {
if (process.env.DOTENV_CONFIG_DEBUG != null) {
options.debug = process.env.DOTENV_CONFIG_DEBUG

@@ -17,0 +17,0 @@ }

@@ -31,2 +31,6 @@ /* @flow */

const NEWLINE = '\n'
const RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*(.*)?\s*$/
const RE_NEWLINES = /\\n/g
// Parses src into an Object

@@ -38,22 +42,28 @@ function parse (src /*: string | Buffer */, options /*: ?DotenvParseOptions */) /*: DotenvParseOutput */ {

// convert Buffers before splitting into lines and processing
src.toString().split('\n').forEach(function (line, idx) {
src.toString().split(NEWLINE).forEach(function (line, idx) {
// matching "KEY' and 'VAL' in 'KEY=VAL'
const keyValueArr = line.match(/^\s*([\w.-]+)\s*=\s*(.*)?\s*$/)
const keyValueArr = line.match(RE_INI_KEY_VAL)
// matched?
if (keyValueArr != null) {
const key = keyValueArr[1]
// default undefined or missing values to empty string
let value = keyValueArr[2] || ''
let val = (keyValueArr[2] || '')
const end = val.length - 1
const isDoubleQuoted = val[0] === '"' && val[end] === '"'
const isSingleQuoted = val[0] === "'" && val[end] === "'"
// expand newlines in quoted values
const len = value ? value.length : 0
if (len > 0 && value.charAt(0) === '"' && value.charAt(len - 1) === '"') {
value = value.replace(/\\n/gm, '\n')
// if single or double quoted, remove quotes
if (isSingleQuoted || isDoubleQuoted) {
val = val.substring(1, end)
// if double quoted, expand newlines
if (isDoubleQuoted) {
val = val.replace(RE_NEWLINES, NEWLINE)
}
} else {
// remove surrounding whitespace
val = val.trim()
}
// remove any surrounding quotes and extra spaces
value = value.replace(/(^['"]|['"]$)/g, '').trim()
obj[key] = value
obj[key] = val
} else if (debug) {

@@ -104,3 +114,2 @@ log(`did not match key and value when parsing line ${idx + 1}: ${line}`)

module.exports.config = config
module.exports.load = config
module.exports.parse = parse
{
"name": "dotenv",
"version": "6.2.0",
"version": "7.0.0",
"description": "Loads environment variables from .env file",

@@ -29,8 +29,8 @@ "main": "lib/main.js",

"devDependencies": {
"decache": "^4.5.0",
"flow-bin": "^0.84.0",
"sinon": "^6.3.5",
"decache": "^4.5.1",
"flow-bin": "^0.92.1",
"sinon": "^7.2.3",
"standard": "^12.0.1",
"standard-markdown": "^5.0.1",
"tap": "^12.0.1"
"tap": "^12.5.1"
},

@@ -37,0 +37,0 @@ "dependencies": {},

@@ -41,4 +41,2 @@ # dotenv

That's it.
`process.env` now has the keys and values you defined in your `.env` file.

@@ -76,3 +74,3 @@

```bash
$ DOTENV_CONFIG_ENCODING=base64 node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/.env
$ DOTENV_CONFIG_ENCODING=latin1 node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/.env
```

@@ -82,5 +80,3 @@

_Alias: `load`_
`config` will read your .env file, parse the contents, assign it to
`config` will read your `.env` file, parse the contents, assign it to
[`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env),

@@ -120,3 +116,3 @@ and return an Object with a `parsed` key containing the loaded content or an `error` key if it failed.

```js
require('dotenv').config({ encoding: 'base64' })
require('dotenv').config({ encoding: 'latin1' })
```

@@ -171,4 +167,7 @@

- empty values become empty strings (`EMPTY=` becomes `{EMPTY: ''}`)
- inner quotes are maintained (think JSON) (`JSON={"foo": "bar"}` becomes `{JSON:"{\"foo\": \"bar\"}"`)
- 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'}`)
- single and double quoted values are escaped (`SINGLE_QUOTE='quoted'` becomes `{SINGLE_QUOTE: "quoted"}`)
- new lines are expanded if in double quotes (`MULTILINE="new\nline"` becomes
- single and double quoted values maintain whitespace from both ends (`FOO=" some value "` becomes `{FOO: ' some value '}`)
- double quoted values expand new lines (`MULTILINE="new\nline"` becomes

@@ -180,5 +179,2 @@ ```

- inner quotes are maintained (think JSON) (`JSON={"foo": "bar"}` becomes `{JSON:"{\"foo\": \"bar\"}"`)
- whitespace is removed from both ends of the value (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'}`)
## FAQ

@@ -264,3 +260,3 @@

1. Preload dotenv: `node --require dotenv/config index.js` (_Note: you do not need to `import` dotenv with this approach_)
2. Import `dotenv/config` instead of `dotenv` (_Note: you do not need to call `dotenv.config()` and must pass options via the command line with this approach_)
2. Import `dotenv/config` instead of `dotenv` (_Note: you do not need to call `dotenv.config()` and must pass options via the command line or environment variables with this approach_)
3. 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)

@@ -280,24 +276,6 @@

## Who's using dotenv
## Who's using dotenv?
Here's just a few of many repositories using dotenv:
[These npm modules depend on it.](https://www.npmjs.com/browse/depended/dotenv)
* [jaws](https://github.com/jaws-framework/jaws-core-js)
* [node-lambda](https://github.com/motdotla/node-lambda)
* [resume-cli](https://www.npmjs.com/package/resume-cli)
* [phant](https://www.npmjs.com/package/phant)
* [adafruit-io-node](https://github.com/adafruit/adafruit-io-node)
* [mockbin](https://www.npmjs.com/package/mockbin)
* [and many more...](https://www.npmjs.com/browse/depended/dotenv)
## Go well with dotenv
Here's some projects that expand on dotenv. Check them out.
* [require-environment-variables](https://github.com/bjoshuanoah/require-environment-variables)
* [dotenv-safe](https://github.com/rolodato/dotenv-safe)
* [envalid](https://github.com/af/envalid)
* [lookenv](https://github.com/RodrigoEspinosa/lookenv)
* [run.env](https://www.npmjs.com/package/run.env)
* [dotenv-webpack](https://github.com/mrsteele/dotenv-webpack)
* [env-path](https://github.com/benrei/env-path)
Projects that expand it often use the [keyword "dotenv" on npm](https://www.npmjs.com/search?q=keywords:dotenv).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc