# dotenv-expand [](https://www.npmjs.com/package/dotenv-expand)
Dotenv-expand adds variable expansion on top of [dotenv](http://github.com/motdotla/dotenv). If you find yourself needing to expand environment variables already existing on your machine, then dotenv-expand is your tool.
[](https://github.com/feross/standard)
[](LICENSE)
[](https://codecov.io/gh/motdotla/dotenv-expand)
## Install
```bash
# Install locally (recommended)
npm install dotenv-expand --save
```
Or installing with yarn? `yarn add dotenv-expand`
## Usage
Create a `.env` file in the root of your project:
```dosini
PASSWORD="s1mpl3"
DB_PASS=$PASSWORD
```
As early as possible in your application, import and configure dotenv and then expand dotenv:
```javascript
const dotenv = require('dotenv')
const dotenvExpand = require('dotenv-expand')
dotenvExpand.expand(dotenv.config())
console.log(process.env) // remove this after you've confirmed it is expanding
```
That's it. `process.env` now has the expanded keys and values you defined in your `.env` file.
```
dotenvExpand.expand(dotenv.config())
...
connectdb(process.env.DB_PASS)
```
### Preload
> Note: Consider using [`dotenvx`](https://github.com/dotenvx/dotenvx) instead of preloading. I am now doing (and recommending) so.
>
> It serves the same purpose (you do not need to require and load dotenv), has built-in expansion support, adds better debugging, and works with ANY language, framework, or platform. – [motdotla](https://github.com/motdotla)
You can use the `--require` (`-r`) [command line option](https://nodejs.org/api/cli.html#cli_r_require_module) to preload dotenv & dotenv-expand. By doing this, you do not need to require and load dotenv or dotenv-expand in your application code. This is the preferred approach when using `import` instead of `require`.
```bash
$ node -r dotenv-expand/config your_script.js
```
The configuration options below are supported as command line arguments in the format `dotenv_config_