Skip to content

Commit

Permalink
Add documentation to README
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Jan 17, 2022
1 parent 0b000ee commit 59da002
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ See [examples](https://github.com/dotenv-org/examples) of using dotenv with vari

Dotenv exposes two functions:

* `dotenv.config`
* `dotenv.parse`
* `config`
* `parse`

### `dotenv.config`
### 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),
Expand All @@ -124,7 +124,7 @@ You can additionally, pass options to `config`.

Default: `path.resolve(process.cwd(), '.env')`

You may specify a custom path if your file containing environment variables is located elsewhere.
Specify a custom path if your file containing environment variables is located elsewhere.

```js
require('dotenv').config({ path: '/custom/path/to/.env' })
Expand All @@ -134,7 +134,7 @@ require('dotenv').config({ path: '/custom/path/to/.env' })

Default: `utf8`

You may specify the encoding of your file containing environment variables.
Specify the encoding of your file containing environment variables.

```js
require('dotenv').config({ encoding: 'latin1' })
Expand All @@ -144,13 +144,23 @@ require('dotenv').config({ encoding: 'latin1' })

Default: `false`

You may turn on logging to help debug why certain keys or values are not being set as you expect.
Turn on logging to help debug why certain keys or values are not being set as you expect.

```js
require('dotenv').config({ debug: process.env.DEBUG })
```

### `dotenv.parse`
##### Override

Default: `false`

Override any environment variables that have already been set on your machine with values from your .env file.

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

### Parse

The engine which parses the contents of your file containing environment
variables is available to use. It accepts a String or Buffer and will return
Expand All @@ -169,7 +179,7 @@ console.log(typeof config, config) // object { BASIC : 'basic' }

Default: `false`

You may turn on logging to help debug why certain keys or values are not being set as you expect.
Turn on logging to help debug why certain keys or values are not being set as you expect.

```js
const dotenv = require('dotenv')
Expand Down
33 changes: 22 additions & 11 deletions lib/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@

export interface DotenvParseOptions {
/**
* Default: `false`
*
* Turn on logging to help debug why certain keys or values are not being set as you expect.
* Defaults to false.
*
* example: `dotenv.parse('KEY=value', { debug: true })`
*/
debug?: boolean;

/**
* Override environment variables that have already been set on your machine with values from your .env file.
* Defaults to false.
*/
override?: boolean;
}

export interface DotenvParseOutput {
Expand All @@ -25,7 +22,7 @@ export interface DotenvParseOutput {
* See https://docs.dotenv.org
*
* @param src - contents to be parsed. example: `'DB_HOST=localhost'`
* @param options - additional options. example: `{ debug: true, override: false }`
* @param options - additional options. example: `{ debug: true }`
* @returns an object with keys and values based on `src`. example: `{ DB_HOST : 'localhost' }`
*/
export function parse<T extends DotenvParseOutput = DotenvParseOutput>(
Expand All @@ -35,24 +32,38 @@ export function parse<T extends DotenvParseOutput = DotenvParseOutput>(

export interface DotenvConfigOptions {
/**
* Default: `path.resolve(process.cwd(), '.env')`
*
* Specify a custom path if your file containing environment variables is located elsewhere.
*
* example: `require('dotenv').config({ path: '/custom/path/to/.env' })`
*/
path?: string;

/**
* Default: `utf8`
*
* Specify the encoding of your file containing environment variables.
*
* example: `require('dotenv').config({ encoding: 'latin1' })`
*/
encoding?: string;

/**
* Default: `false`
*
* Turn on logging to help debug why certain keys or values are not being set as you expect.
* Defaults to false.
*
* example: `require('dotenv').config({ debug: process.env.DEBUG })`
*/
debug?: boolean;

/**
* Override environment variables that have already been set on your machine with values from your .env file.
* Defaults to false.
* Default: `false`
*
* Override any environment variables that have already been set on your machine with values from your .env file.
*
* example: `require('dotenv').config({ override: true })`
*/
override?: boolean;
}
Expand Down
1 change: 0 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const NEWLINES_MATCH = /\r\n|\n|\r/
// Parses src into an Object
function parse (src, options) {
const debug = Boolean(options && options.debug)
const override = Boolean(options && options.override)
const obj = {}

// convert Buffers before splitting into lines and processing
Expand Down

0 comments on commit 59da002

Please sign in to comment.