npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

azure-key-vault-env

v2.0.0

Published

manage your environment variables using azure key vault

Downloads

28

Readme

azure-key-vault-env

Manage your environment variables using azure key vault.

Problem

  • When your application has many environment variables, they become difficult to manage.
  • Securely sharing env file with team members is time-consuming.
  • Managing multiple environments (local, demo, staging, production,...) again introduces some more challenges.

Solution

If you are already using azure, manage your environment variables using key vault. It's a good service with many benefits. (learn more)

  • create a azure key vault.
  • create a service principal with access to above key vault.
  • use this package to set up and load env.

Installation

npm install azure-key-vault-env

Usage


Initial Setup

  1. Setup azure key-vault and get following config.
  • KEY_VAULT_URI: The keyvault uri in Azure
  • AZURE_TENANT_ID: The tenant ID in Azure Active Directory
  • AZURE_CLIENT_ID: The application (client) ID registered in the AAD tenant
  • AZURE_CLIENT_SECRET: The client secret for the registered application

Add these in your environment.

  1. Prepare an envKeys file with all environment variables.
const envKeys = {

    // Database    
    DB_HOST: '',
    DB_NAME: '',
    DB_USER: '',
    DB_PASS: '',

    // Any other variables
}
  1. Run setup to send all data to azure key-vault.

const manager = require('azure-key-vault-env');

// Your environment variables.
const envKeys = {
       
    // Database    
    DB_HOST: '',
    DB_NAME: '',
    DB_USER: '',
    DB_PASS: '',

    // Any other variables
} 

const result = await manager.setup({ envKeys });

Now all your variables are uploaded to key-vault.


Load Variables in your app.

const manager = require('azure-key-vault-env');

// Your environment variables file with just keys.
const envKeys = {
       
    // Database    
    DB_HOST: '',
    DB_NAME: '',
    DB_USER: '',
    DB_PASS: '',

    // Any other variables
} 

// load environment variables
const result = await manager.init({ envKeys });

Example with express.js

/**
 * Entry File
 */

require('dotenv').config();
const azureKeyVaultEnv = require('azure-key-vault-env');
const envKeys = require('INSERT___PATH_TO_YOUR_ENV_KEYS_FILE'); 

/****************************************************************************************************
 *  Load environment variables from key-vault.
 *  Target environment variables are defined in envKeys.
 ****************************************************************************************************/

module.exports = azureKeyVaultEnv
    .init({ envKeys })
    .then(async () => {
        
        // setup your database connection or other operations

        const express = require('express');
        const app = express();
        const port = 3000;
        const server = require('http').Server(app);
        
        server.listen(port, (err) => {

            if (err) {

                return logger.error(`API: Failure to listen: ${err.message} | ${err.name}`);

            }

            logger.info(`Express app live @PORT: ${port}.`);

        });

        return app;

    }).catch(error => {

        logger.error(error);

    });