dotenv-expand
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Dotenv-expand is a useful tool for adding variable expansion on top of dotenv. It is useful in scenarios where you need to expand environment variables that already exist on your machine. The package allows you to define your environment variables within a .env
file and automatically expand these variables within your JavaScript code.
To use dotenv-expand, you would first need to install it via npm by running the command npm install dotenv-expand
or if you are using yarn, it would be yarn add dotenv-expand
. You should then create a .env
file in the root directory of your project and define your environment variables within this file. For example:
PASSWORD="s1mpl3"
DB_PASS=$PASSWORD
Then, within your application code, you should import and configure dotenv and then expand dotenv as shown:
var dotenv = require('dotenv')
var dotenvExpand = require('dotenv-expand')
var myEnv = dotenv.config()
dotenvExpand.expand(myEnv)
console.log(process.env)
This way, you can access the expanded values of the keys that you defined in your .env
file through process.env
. There is also a feature for preloading dotenv & dotenv-expand where you won't need require and load dotenv or dotenv-expand in your code.
The official documentation of dotenv-expand can be found on its GitHub page at https://github.com/motdotla/dotenv-expand. The documentation covers features such as usage, installation, variable expansion rules, and dotenv-expand's API. For further examples of using dotenv-expand, the tests/.env file in the package's GitHub repository contains both simple and complex examples of variable expansion in a .env
file. The repository also contains a comprehensive guide on contributing to dotenv-expand.