+20
-0
@@ -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 |
+62
-63
@@ -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 |
+17
-10
| { | ||
| "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" | ||
| } | ||
| } |
+24
-13
@@ -10,2 +10,3 @@ # dotenv | ||
| [](https://github.com/feross/standard) | ||
| [](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) |
Sorry, the diff of this file is not supported yet
| # Contributing | ||
| 1. Fork it | ||
| 2. `npm install` | ||
| 3. Create your feature branch (`git checkout -b my-new-feature`) | ||
| 4. Commit your changes (`git commit -am 'Added some feature'`) | ||
| 5. `npm test` | ||
| 6. Push to the branch (`git push origin my-new-feature`) | ||
| 7. Create new Pull Request | ||
| ## Testing | ||
| We use [lab](https://github.com/hapijs/lab) and [should](https://github.com/shouldjs/should.js) to write BDD test. Run our test suite with this command: | ||
| ``` | ||
| npm test | ||
| ``` | ||
| ## Code Style | ||
| We use [standard](https://www.npmjs.com/package/standard) and [editorconfig](http://editorconfig.org) to maintain code style and best practices. Please make sure your PR adheres to the guides by running: | ||
| ``` | ||
| npm run lint | ||
| ``` |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
218
5.31%14024
-25.06%8
33.33%6
-33.33%