Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 2.0.0 to 3.0.0

20

CHANGELOG.md

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

## [3.0.0]
### Added
- `verbose` option will log any error messages. Off by default.
- parses email addresses correctly
- allow importing config method directly in ES6
### Changed
- Suppress error messages by default ([#154](https://github.com/motdotla/dotenv/pull/154))
- Ignoring more files for NPM to make package download smaller
### Fixed
- False positive test due to case-sensitive variable ([#124](https://github.com/motdotla/dotenv/pull/124))
### Removed
- `silent` option removed in favor of `verbose`
## [2.0.0] - 2016-01-20

@@ -9,0 +29,0 @@ ### Added

125

lib/main.js

@@ -5,79 +5,78 @@ 'use strict'

module.exports = {
/*
* Main entry point into dotenv. Allows configuration before loading .env
* @param {Object} options - valid options: path ('.env'), encoding ('utf8')
* @returns {Boolean}
*/
config: function (options) {
var path = '.env'
var encoding = 'utf8'
var silent = false
/*
* Parses a string or buffer into an object
* @param {String|Buffer} src - source to be parsed
* @returns {Object}
*/
function parse (src) {
var obj = {}
if (options) {
if (options.silent) {
silent = options.silent
// convert Buffers before splitting into lines and processing
src.toString().split('\n').forEach(function (line) {
// matching "KEY' and 'VAL' in 'KEY=VAL'
var keyValueArr = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/)
// matched?
if (keyValueArr != null) {
var key = keyValueArr[1]
// default undefined or missing values to empty string
var value = keyValueArr[2] ? keyValueArr[2] : ''
// expand newlines in quoted values
var len = value ? value.length : 0
if (len > 0 && value.charAt(0) === '"' && value.charAt(len - 1) === '"') {
value = value.replace(/\\n/gm, '\n')
}
if (options.path) {
path = options.path
}
if (options.encoding) {
encoding = options.encoding
}
}
try {
// specifying an encoding returns a string instead of a buffer
var parsedObj = this.parse(fs.readFileSync(path, { encoding: encoding }))
// remove any surrounding quotes and extra spaces
value = value.replace(/(^['"]|['"]$)/g, '').trim()
Object.keys(parsedObj).forEach(function (key) {
process.env[key] = process.env[key] || parsedObj[key]
})
return parsedObj
} catch (e) {
if (!silent) {
console.error(e)
}
return false
obj[key] = value
}
},
})
/*
* Parses a string or buffer into an object
* @param {String|Buffer} src - source to be parsed
* @returns {Object}
*/
parse: function (src) {
var obj = {}
return obj
}
// convert Buffers before splitting into lines and processing
src.toString().split('\n').forEach(function (line) {
// matching "KEY' and 'VAL' in 'KEY=VAL'
var keyValueArr = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/)
// matched?
if (keyValueArr != null) {
var key = keyValueArr[1]
/*
* Main entry point into dotenv. Allows configuration before loading .env
* @param {Object} options - valid options: path ('.env'), encoding ('utf8')
* @returns {Boolean}
*/
function config (options) {
var path = '.env'
var encoding = 'utf8'
var verbose = false
// default undefined or missing values to empty string
var value = keyValueArr[2] ? keyValueArr[2] : ''
if (options) {
if (options.verbose) {
verbose = options.verbose
}
if (options.path) {
path = options.path
}
if (options.encoding) {
encoding = options.encoding
}
}
// expand newlines in quoted values
var len = value ? value.length : 0
if (len > 0 && value.charAt(0) === '\"' && value.charAt(len - 1) === '\"') {
value = value.replace(/\\n/gm, '\n')
}
try {
// specifying an encoding returns a string instead of a buffer
var parsedObj = parse(fs.readFileSync(path, { encoding: encoding }))
// remove any surrounding quotes and extra spaces
value = value.replace(/(^['"]|['"]$)/g, '').trim()
obj[key] = value
}
Object.keys(parsedObj).forEach(function (key) {
process.env[key] = process.env[key] || parsedObj[key]
})
return obj
return parsedObj
} catch (e) {
if (verbose) {
console.error('dotenv failed to parse and/or populate:' + e.message)
}
return false
}
}
module.exports.load = module.exports.config
module.exports.config = config
module.exports.load = config
module.exports.parse = parse
{
"name": "dotenv",
"version": "2.0.0",
"version": "3.0.0",
"description": "Loads environment variables from .env file",
"main": "lib/main.js",
"scripts": {
"test": "lab test/* --coverage",
"posttest": "npm run lint",
"lint": "standard"
"pretest": "npm run lint",
"test": "lab test/* -r lcov | coveralls",
"lint": "standard",
"postlint": "npm run lint-md",
"lint-md": "standard-markdown"
},

@@ -29,9 +31,14 @@ "repository": {

"babel": "5.8.23",
"lab": "5.17.0",
"semver": "5.0.3",
"should": "7.1.0",
"sinon": "1.16.1",
"standard": "5.3.0"
"coveralls": "^2.11.9",
"lab": "11.1.0",
"semver": "5.3.0",
"should": "11.1.1",
"sinon": "1.17.6",
"standard": "8.4.0",
"standard-markdown": "2.2.0"
},
"dependencies": {}
"dependencies": {},
"engines": {
"node": ">=4.6.0"
}
}

@@ -10,2 +10,3 @@ # dotenv

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![Coverage Status](https://img.shields.io/coveralls/motdotla/dotenv/master.svg?style=flat-square)](https://coveralls.io/github/motdotla/dotenv?branch=coverall-intergration)

@@ -23,3 +24,3 @@ ## Install

```javascript
require('dotenv').config();
require('dotenv').config()
```

@@ -42,2 +43,3 @@

```javascript
var db = require('db')
db.connect({

@@ -47,3 +49,3 @@ host: process.env.DB_HOST,

password: process.env.DB_PASS
});
})
```

@@ -76,11 +78,10 @@

#### Silent
#### Verbose
Default: `false`
Dotenv outputs a warning to your console if missing a `.env` file. Suppress
this warning using silent.
All errors are suppressed by default. Set this to `true` for more logging.
```js
require('dotenv').config({silent: true});
require('dotenv').config({verbose: true})
```

@@ -96,3 +97,3 @@

```js
require('dotenv').config({path: '/custom/path/to/your/env/vars'});
require('dotenv').config({path: '/custom/path/to/your/env/vars'})
```

@@ -108,3 +109,3 @@

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

@@ -119,5 +120,5 @@

```js
var dotenv = require('dotenv');
var buf = new Buffer('BASIC=basic');
var config = dotenv.parse(buf); // will return an object
var dotenv = require('dotenv')
var buf = new Buffer('BASIC=basic')
var config = dotenv.parse(buf) // will return an object
console.log(typeof config, config) // object { BASIC : 'basic' }

@@ -164,2 +165,13 @@ ```

If you want to override `process.env` you can do something like this:
```javascript
const fs = require('fs')
const dotenv = require('dotenv')
const envConfig = dotenv.parse(fs.readFileSync('.env.override'))
for (var k in envConfig) {
process.env[k] = envConfig[k]
}
```
### Can I customize/write plugins for dotenv?

@@ -184,3 +196,2 @@

## Contributing Guide

@@ -202,3 +213,2 @@

* [npm](https://github.com/npm/newww)
* [jaws](https://github.com/jaws-framework/jaws-core-js)

@@ -218,1 +228,2 @@ * [node-lambda](https://github.com/motdotla/node-lambda)

* [dotenv-safe](https://github.com/rolodato/dotenv-safe)
* [envalid](https://github.com/af/envalid)
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