# mountenv

> mount/load .env files with support for .env.prod/.env.dev files

Latest version **0.5.1** (published 2023-05-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install mountenv
pnpm add mountenv
yarn add mountenv
bun add mountenv
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.1 |
| Published | 2023-05-17 |
| First published | 2017-11-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 574 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | danielkalen |
| Maintainers | danielkalen |
| Keywords | dotenv, loadenv, env, environment, variable, mount, node_env |

## Links

- npm: https://www.npmjs.com/package/mountenv
- Repository: https://github.com/danielkalen/mountenv
- Homepage: https://github.com/danielkalen/mountenv#readme
- Issues: https://github.com/danielkalen/mountenv/issues
- npm.io page: https://npm.io/package/mountenv

## Dependencies (3)

- [dotenv](https://npm.io/package/dotenv.md) ^4.0.0
- [extend](https://npm.io/package/extend.md) ^3.0.1
- [fs-jetpack](https://npm.io/package/fs-jetpack.md) ^1.2.0

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 0.5.1 (latest) — 2023-05-17
- 0.5.0 — 2023-05-17
- 0.4.1 — 2018-12-06
- 0.4.0 — 2018-07-25
- 0.3.1 — 2018-06-14
- 0.3.0 — 2018-06-06
- 0.2.0 — 2018-03-08
- 0.1.1 — 2017-12-21
- 0.1.0 — 2017-12-21
- 0.0.2 — 2017-12-01
- 0.0.1 — 2017-11-22

## README

# mountenv
[![Build Status](https://travis-ci.org/danielkalen/mountenv.svg?branch=master)](https://travis-ci.org/danielkalen/mountenv)
[![Code Climate](https://codeclimate.com/github/danielkalen/mountenv/badges/gpa.svg)](https://codeclimate.com/github/danielkalen/mountenv)
[![NPM](https://img.shields.io/npm/v/mountenv.svg)](https://npmjs.com/package/mountenv)

Features:
- extends [dotenv](https://npmjs.com/package/dotenv) functionality
- supports loading .env files under `CWD` or a specific directory
- auto loads `.env.dev` when `NODE_ENV === 'development'` (in addition)
- auto loads `.env.prod` when `NODE_ENV === 'production'` (in addition)
- auto loads `.env.staging` when `NODE_ENV === 'staging'` (in addition)
- auto loads `.env.test` when `NODE_ENV === 'test'` (in addition)


![preview](doc/preview.jpg?raw=true)


### `mountenv.load([dir])`
Loads env files in the provided directory and extends current process environment. `dir` defaults to `process.cwd()`.

```javascript
require('mountenv').load()
```


### `mountenv.get([dir])`
Loads env files in the provided directory and returns the result object (does NOT extend current process environment). `dir` defaults to `process.cwd()`.

```javascript
var result = require('mountenv').get('./config/')
```


### `mountenv.getAll([dir])`
Loads env files in the provided directory and returns the result object including definitions from current `process.env` (does NOT extend current process environment). `dir` defaults to `process.cwd()`.

```javascript
var result = require('mountenv').get('./config/')
```


### `mountenv.parse(string)`
Parses the provided string as an env file and returns the result object.

```javascript
var env = `
    ABC=123
    DEF=456
`
var result = require('mountenv').parse(env)
```


## Custom env file name
By default, `mountenv` looks for files starting with `.env` in the `cwd`:
```
├── .env
├── .env.dev
└── .env.prod
└── .env.test
```

If you want `mountenv` to look for files with a different prefix, pass `{basename:'mycustomname'}` as the 2nd argument for any of the above mentioned methods:
```javascript
require('mountenv').load(null, {basename:'.myenv'})
```


## Variable expansion
By default variable expansion is turned on so if you want `mountenv` to resolve nested variables pass `{expand:true}` as the 2nd argument for any of the above mentioned methods:
```javascript
require('mountenv').parse(`
    PROJECT_DIR=$HOME/this-project
`, {expand:true}) //-> {PROJECT_DIR: 'Users/thisuser/this-project'}
```


## Syntax Rules
see [dotenv's rules section](https://www.npmjs.com/package/dotenv#rules).


## License
MIT © [Daniel Kalen](https://github.com/danielkalen)

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