
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
dotenv-azure
Advanced tools
Load environment variables from Azure's services App Configuration, Key Vault or a .env file
Load environment variables from Azure's services App Configuration, Key Vault or a .env file with an api similar to dotenv.
Maybe you want to securely store secrets in Azure Key Vault, but you also have configurations and feature flags stored in Azure App Configuration and you have to override some of those configurations with a .env file when running your app locally.
Or you have a complex configuration data that you want to centralize it somewhere. Azure recommends the usage of App Config for configuration and Key Vault for secrets. You can read more about it here.
With dotenv-azure you can easily retrieve your app's configurations and secrets from these 3 sources and merge them into process.env.
If you would like to know more about App Configuration and Key Vault, you may want to review What is App Configuration? and What is Azure Key Vault?
Install with npm
npm install dotenv-azure
or with yarn
yarn add dotenv-azure
.env file:AZURE_APP_CONFIG_CONNECTION_STRING="generated-app-config-conneciton-string"
If you want to use Key Vault alongside with App Configuration you have to create a service principal and configure its access to Azure resources. You can follow this guide.
Once you have AZURE_CLIENT_ID(appId), AZURE_CLIENT_SECRET(password) and AZURE_TENANT_ID(tenant) you have to set them as environment variables. You can do this with export in Bash or put them in a .env file:
In production, if you are using Azure Managed Identities, you don't have to set these variables.
AZURE_CLIENT_ID="generated-app-ID"
AZURE_CLIENT_SECRET="random-password"
AZURE_TENANT_ID="tenant-ID"
If you have a configuration in App Configuration with the content type application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8 then dotenv-azure will try to load it from Key Vault.
You can add a Key Vault reference to App Configuration in the Azure portal:
Now when you call the .config() method, the value of your key vault secret will be set to process.env:
const { DotenvAzure } = require('dotenv-azure')
async function main() {
await new DotenvAzure().config()
console.log(process.env.DATABASE_URL) // prints your secret value
}
main()
You should call dotenv-azure before the initialization of your app. Since the method .config() returns a promise, you have to call it inside an async function:
const { DotenvAzure } = require('dotenv-azure')
async function main() {
const dotenvAzure = new DotenvAzure()
const { parsed } = await dotenvAzure.config()
// `parsed` is an object containing:
// - Your App Config configurations
// - Key Vault secrets
// - Environment variables defined in a .env file
// - and environment variables that weren't overwritten
console.log(parsed)
// process.env now has the keys and values from the parsed result
console.log(process.env)
// start app
// ...
}
main()
You can use the --require (-r) command line option to preload dotenv-azure. By doing this, you do not need to require and load dotenv-azure in your application code.
node -r dotenv-azure/config your_script.js
To enable safe mode you should require config-safe:
node -r dotenv-azure/config-safe your_script.js
dotenv-azure uses dotenv under the covers, so the same rules for .env files apply here as well.
When populating process.env dotenv-azure will follow these steps:
.env file, and not present in the environemnt, process.env will be populated with those values.dotenv-azure will search for the required environment variables to access azure's services after loading variables from the .env file..env file or in the Azure App Configuration, where the value is prefixed with kv: what follows is assumed to be the secret identifier of a secret stored in Key Vault, and so dotenv-azure will attempt to populate the value from Key Vault.You can pass a safe option to validate your variables from a .env.example file like dotenv-safe:
const { DotenvAzure } = require('dotenv-azure')
const dotenvAzure = new DotenvAzure()
async function main() {
await dotenvAzure.config({
safe: true,
allowEmptyValues: true,
example: './.my-env-example-filename',
})
}
main()
.config() and .parse() have the same options as dotenv and dotenv-safe
You can read the api documentation here.
This project follows the all-contributors specification. Contributions of any kind are welcome!
Daniel Sousa 💻 📖 🚇 🚧 ⚠️ | Mahesh Sasidharan 📖 |
FAQs
Load environment variables from Azure's services App Configuration, Key Vault or a .env file
The npm package dotenv-azure receives a total of 201 weekly downloads. As such, dotenv-azure popularity was classified as not popular.
We found that dotenv-azure demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.