Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stagas/read-dotenv

read a .env file into an object
https://github.com/stagas/read-dotenv

env environment environment-variables nodejs

Last synced: 14 days ago
JSON representation

read a .env file into an object

Awesome Lists containing this project

README

        

# read-dotenv

read a .env file into an object

## Installation

```sh
$ npm install read-dotenv --save
```

## Usage

```js
import dotenv from 'read-dotenv'
```

## Example

```sh
# .env
PORT=7777
HOST=my.host.com
```

```js
// app.js
import dotenv from 'read-dotenv'

const env = dotenv({
PORT: 3000,
HOST: 'localhost',
SOME: 'other option'
})

// `env` is now:
{
PORT: 7777,
HOST: 'my.host.com',
SOME: 'other option',
}

```

## API

### ▸ **dotenv**(`env?`, `root?`): _`Record`_

#### Parameters

| Name | Type | Description |
| :----- | :-------------------- | :----------------------------------------------------- |
| `env` | `Record` | The environment default object |
| `root` | `string` | The path where `.env` lives (default: `process.cwd()`) |

## License

MIT