diff options
Diffstat (limited to 'deps/npm/node_modules/libnpx/node_modules/dotenv/README.md')
-rw-r--r-- | deps/npm/node_modules/libnpx/node_modules/dotenv/README.md | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/deps/npm/node_modules/libnpx/node_modules/dotenv/README.md b/deps/npm/node_modules/libnpx/node_modules/dotenv/README.md index 90836a34b7..4665fd3962 100644 --- a/deps/npm/node_modules/libnpx/node_modules/dotenv/README.md +++ b/deps/npm/node_modules/libnpx/node_modules/dotenv/README.md @@ -5,6 +5,7 @@ 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. [![BuildStatus](https://img.shields.io/travis/motdotla/dotenv/master.svg?style=flat-square)](https://travis-ci.org/motdotla/dotenv) +[![Build status](https://ci.appveyor.com/api/projects/status/rnba2pyi87hgc8xw/branch/master?svg=true)](https://ci.appveyor.com/project/maxbeatty/dotenv/branch/master) [![NPM version](https://img.shields.io/npm/v/dotenv.svg?style=flat-square)](https://www.npmjs.com/package/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) @@ -27,7 +28,7 @@ Create a `.env` file in the root directory of your project. Add environment-specific variables on new lines in the form of `NAME=VALUE`. For example: -``` +```dosini DB_HOST=localhost DB_USER=root DB_PASS=s1mpl3 @@ -38,7 +39,7 @@ That's it. `process.env` now has the keys and values you defined in your `.env` file. ```javascript -var db = require('db') +const db = require('db') db.connect({ host: process.env.DB_HOST, username: process.env.DB_USER, @@ -48,8 +49,7 @@ db.connect({ ### Preload -If you are using iojs-v1.6.0 or later, you can use the `--require` (`-r`) command line option to preload dotenv. By doing this, you do not need to require and load dotenv in your application code. - +You can use the `--require` (`-r`) command line option to preload dotenv. By doing this, you do not need to require and load dotenv in your application code. This is the preferred approach when using `import` instead of `require`. ```bash $ node -r dotenv/config your_script.js @@ -67,20 +67,31 @@ _Alias: `load`_ `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. +and return an Object with a `parsed` key containing the loaded content or an `error` key if it failed. + +```js +const result = dotenv.config() + +if (result.error) { + throw result.error +} + +console.log(result.parsed) +``` + You can additionally, pass options to `config`. ### Options #### Path -Default: `.env` +Default: `path.resolve(process.cwd(), '.env')` You can specify a custom path if your file containing environment variables is named or located differently. ```js -require('dotenv').config({path: '/custom/path/to/your/env/vars'}) +require('dotenv').config({path: '/full/custom/path/to/your/env/vars'}) ``` #### Encoding @@ -101,9 +112,9 @@ variables is available to use. It accepts a String or Buffer and will return an Object with the parsed keys and values. ```js -var dotenv = require('dotenv') -var buf = new Buffer('BASIC=basic') -var config = dotenv.parse(buf) // will return an object +const dotenv = require('dotenv') +const buf = new Buffer('BASIC=basic') +const config = dotenv.parse(buf) // will return an object console.log(typeof config, config) // object { BASIC : 'basic' } ``` @@ -123,6 +134,7 @@ The parsing engine currently supports the following rules: line'} ``` - 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 @@ -175,6 +187,40 @@ For `dotenv@2.x.x`: Use [dotenv-expand](https://github.com/motdotla/dotenv-expan For `dotenv@1.x.x`: We haven't been presented with a compelling use case for expanding variables and believe it leads to env vars that are not "fully orthogonal" as [The Twelve-Factor App](http://12factor.net/config) outlines.<sup>[[1](https://github.com/motdotla/dotenv/issues/39)][[2](https://github.com/motdotla/dotenv/pull/97)]</sup> Please open an issue if you have a compelling use case. +### How do I use dotenv with `import`? + +ES2015 and beyond offers modules that allow you to `export` any top-level `function`, `class`, `var`, `let`, or `const`. + +> 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. +> +> – [ES6 In Depth: Modules](https://hacks.mozilla.org/2015/08/es6-in-depth-modules/) + +You must run `dotenv.config()` before referencing any environment variables. Here's an example of problematic code: + +`errorReporter.js`: + +```js +import { Client } from 'best-error-reporting-service' + +export const client = new Client(process.env.BEST_API_KEY) +``` + +`index.js`: + +```js +import dotenv from 'dotenv' +dotenv.config() + +import errorReporter from './errorReporter' +errorReporter.client.report(new Error('faq example')) +``` + +`client` will not be configured correctly because it was constructed before `dotenv.config()` was executed. There are (at least) 3 ways to make this work. + +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_) +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) + ## Contributing Guide See [CONTRIBUTING.md](CONTRIBUTING.md) @@ -206,3 +252,6 @@ 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) |