Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: motdotla/dotenv
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.0.0
Choose a base ref
...
head repository: motdotla/dotenv
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.0.0
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Dec 23, 2016

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    2d84b5a View commit details
  2. v4.0.0

    maxbeatty committed Dec 23, 2016

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    fdd0923 View commit details
Showing with 30 additions and 34 deletions.
  1. +15 −2 CHANGELOG.md
  2. +4 −13 README.md
  3. +2 −9 lib/main.js
  4. +1 −1 package.json
  5. +8 −9 test/main.js
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [3.0.0]
## [4.0.0] - 2016-12-23
### Changed

- Return Object with parsed content or error instead of false ([#165](https://github.com/motdotla/dotenv/pull/165)).


### Removed

- `verbose` option removed in favor of returning result.


## [3.0.0] - 2016-12-20
### Added

- `verbose` option will log any error messages. Off by default.
@@ -56,7 +67,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Removed
- support for multiple `.env` files. should always use one `.env` file for the current environment

[Unreleased]: https://github.com/motdotla/dotenv/compare/v2.0.0...HEAD
[Unreleased]: https://github.com/motdotla/dotenv/compare/v4.0.0...HEAD
[4.0.0]: https://github.com/motdotla/dotenv/compare/v3.0.0...v4.0.0
[3.0.0]: https://github.com/motdotla/dotenv/compare/v2.0.0...v3.0.0
[2.0.0]: https://github.com/motdotla/dotenv/compare/v1.2.0...v2.0.0
[1.2.0]: https://github.com/motdotla/dotenv/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/motdotla/dotenv/compare/v1.0.0...v1.1.0
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -65,22 +65,13 @@ $ node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/your/e

_Alias: `load`_

`config` will read your .env file, parse the contents, and assign it to
[`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env). You can additionally, pass options to
`config`.
`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),
and return an Object with a _parsed_ key containing the loaded content or an _error_ key if it failed.
You can additionally, pass options to `config`.

### Options

#### Verbose

Default: `false`

All errors are suppressed by default. Set this to `true` for more logging.

```js
require('dotenv').config({verbose: true})
```

#### Path

Default: `.env`
11 changes: 2 additions & 9 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -45,12 +45,8 @@ function parse (src) {
function config (options) {
var path = '.env'
var encoding = 'utf8'
var verbose = false

if (options) {
if (options.verbose) {
verbose = options.verbose
}
if (options.path) {
path = options.path
}
@@ -67,12 +63,9 @@ function config (options) {
process.env[key] = process.env[key] || parsedObj[key]
})

return parsedObj
return { parsed: parsedObj }
} catch (e) {
if (verbose) {
console.error('dotenv failed to parse and/or populate:' + e.message)
}
return false
return { error: e }
}
}

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dotenv",
"version": "3.0.0",
"version": "4.0.0",
"description": "Loads environment variables from .env file",
"main": "lib/main.js",
"scripts": {
17 changes: 8 additions & 9 deletions test/main.js
Original file line number Diff line number Diff line change
@@ -74,21 +74,20 @@ describe('dotenv', function () {
done()
})

it('catches any errors thrown from reading file or parsing', function (done) {
var errorStub = s.stub(console, 'error')
readFileSyncStub.throws()
it('returns parsed object', function (done) {
var env = dotenv.config()

dotenv.config().should.eql(false)
errorStub.called.should.be.false // because verbose is off
env.should.not.have.property('error')
env.parsed.should.eql({ test: 'val' })
done()
})

it('takes option for exposing errors', function (done) {
var errorStub = s.stub(console, 'error')
it('returns any errors thrown from reading file or parsing', function (done) {
readFileSyncStub.throws()

dotenv.config({verbose: true}).should.eql(false)
errorStub.callCount.should.eql(1)
var env = dotenv.config()
env.should.have.property('error')
env.error.should.be.instanceOf(Error)
done()
})
})