# dotenv-plus-options

> Config module to read .env config files and constructor options mixing in config.options

Latest version **1.0.4** (published 2019-10-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install dotenv-plus-options
pnpm add dotenv-plus-options
yarn add dotenv-plus-options
bun add dotenv-plus-options
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2019-10-06 |
| First published | 2019-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.17.1 |
| Dependencies | 1 |
| Unpacked size | 21.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Adolfo Segura Hall |
| Maintainers | adsegura |
| Keywords | dotenv, config, options |

## Links

- npm: https://www.npmjs.com/package/dotenv-plus-options
- Repository: https://github.com/adsegura/dotenv-plus-options
- Homepage: https://github.com/adsegura/dotenv-plus-options/blob/master/README.md
- Issues: https://github.com/adsegura/dotenv-plus-options/issues
- npm.io page: https://npm.io/package/dotenv-plus-options

## Dependencies (1)

- [dotenv](https://npm.io/package/dotenv.md) ^8.1.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2019-10-06
- 1.0.3 — 2019-10-06
- 1.0.2 — 2019-10-06
- 1.0.1 — 2019-10-06
- 1.0.0 — 2019-10-06

## README

[![Build Status](https://api.travis-ci.org/adsegura/dotenv-plus-options.svg?branch=master)](https://travis-ci.org/adsegura/dotenv-plus-options)

# dotenv-plus-options
This module loads environment variables from a .env file, if there is one .env file at CWD, (with dotenv package)
and **any options given to the constructor**, mixing it all into `config.options`

Constructor `options` **always takes preference** over options from `.env` file.

## Install
```sh
$> npm i dotenv-plus-options
```
## Prerequisites
* NodeJs `>=v6.17.1 (npm v3.10.10)`

# Usage 

### Instantiate Config module
```js
const {Config} = require('dotenv-plus-options');
let config;

config = new Config();
config = new Config(options);
config = new Config(options, dotenv_options);
config = new Config(null, dotenv_options);

console.log(config.options);
```

### Example Extends Config Class
```js
/**
 .env file on CWD:
 DB_USER=John
 ALLOWED=["foo", "bar"]
 OBJ={"id": 1, "op": ["one","two"]}
 */

const {Config} = require('dotenv-plus-options');

class App extends Config {
    constructor(opt){
        super(opt)
    }
}

const app = new App({db_user: 'root', baz: 2});

console.log(app.options);

/**
 {
  db_user: 'root', //constructor options always takes preference
  allowed: [ 'foo', 'bar' ],
  obj: { id: 1, op: [ 'one', 'two' ] },
  baz: 2
  }
 */
```

### dotenv options
* [dotenv options](https://github.com/motdotla/dotenv#options)

### Errors 
Only one error is thrown, named `AdsegConfigError` 
when you force dotenv custom .env path and dotenv cannot parse it.
```js
const {Config} = require('dotenv-plus-options');

config = new Config(options, {path: 'nonExistingEnvFile'});

//or

config = new Config(null, {path: 'nonExistingEnvFile'});

//throws AdsegConfigError
````

# Tests
```bash
> npm run test
```

### Dependencies
* [dotenv module](https://github.com/motdotla/dotenv#readme)

### Contributing
Pull requests are welcome.

### License
[MIT](https://choosealicense.com/licenses/mit/)

---
_Source: https://npm.io/package/dotenv-plus-options · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
