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

@handstudio/envman

v1.0.11

Published

A tiny environment variables manager. Powered by AWS SSM/Parameter Store.

Downloads

3

Readme

envman

A little environment manager for AWS SSM / ParameterStore / Dotenv

build

 __ _ ____ ___ __ ___ __ _ _ __ _ __
/ _ \ '_ \ \ / / '_ ` _ \ / _` | '_ \
| __/ | | \ V /| | | | | | (_| | | | |
\___|_| |_|\_/ |_| |_| |_|\__,_|_| |_|

How to install

Before install

envman is hosted in a private NPM repository, so make sure you have access to handstudio's private repo. check out your $HOME/.npmrc file.

@handstudio:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=GITHUB_TOKEN

Install locally, as a library

npm install --save @handstudio/envman

Install globally, as a CLI utility

npm install -g @handstudio/envman

Usages

Keys of environment variables

Prints a list of all environment variable keys.

# envman keys
envman keys

Printing environment variables

Assume that there are stored environment variables in AWS ParameterStore. you can env-variables like followings:

# envman print --key <key>
envman print \
  --key /NCDinos/BatchWorker/Stage \

  --output json \
  --profile someAwsProfileName

The --output flag can be one of json, dotenv, ebextensions.

It is also possible to read environment variables from multiple keys.

# envman print --key <key1> --key <key2>
envman print \
  --key /NCDinos/BatchWorker/Stage \
  --key /NCDinos/Common/Stage \

  --output json \
  --profile someAwsProfileName

If you're using AWS STS with MFA(Multi Factor Authorization), use --use-mfa flag.

envman print \
  --key /Test/Stage \
  --use-mfa

Saving environment variables into storage

Parameter can be saved in environment variable storage through --env: KEY VALUE command.

# envman save <key> --env:K1 V1 --env:K2 V2 ...
envman save /NCDinos/Common \
  --env:MASTER_KEY somemasterkey \
  --env:IV someiv \
  --profile ncdinos

Suppose that the environment variables are stored in the form of a dotenv file locally. You can store it in a remote environment variable repository as follows:

# envman save <key> --input [dotenv | json] --path <path>
envman save /NCDinos/Common \
  --input dotenv \
  --path $HOME/test-env.env \
  --profile ncdinos

The --input flag can have the following values: json, dotenv

Usage with node.js projects

With shell script

env \
  $(envman print \
    --key /ncdinos/auction-mall/stage \
    --profile ncdinos \
  ) node app.js

Of course, you can also use ENVMAN as a npm script as follows. The following sample package.json shows that using ENVMAN and node.js project together.

{
  "name": "env-test",
  "version": "1.0.0",
  "description": "envman test project",
  "main": "app.js",
  "scripts": {
    "start": "env $(envman print --key /ncdinos/auction-mall/stage --profile ncdinos) node app.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {},
  "devDependencies": {
    "@handstudio/envman": "^1.0.1"
  }
}

With node --require option

You can use the following method inspired by dotenv.

ENVMAN_KEY=/NCDinos/Common \
  node -r @handstudio/envman/config yourApp.js

By using ENVMAN_KEY, you can specify the key of the environment variable you want to load. If you need a separate AWS profile name, you can use it as follows by using ENVMAN_AWS_PROFILE :

ENVMAN_KEY=/NCDinos/Common \
ENVMAN_AWS_PROFILE=ncdinos \ # your AWS profile name
  node -r @handstudio/envman/config yourApp.js

Loading environment variables is basically an asynchronous operation. for this reason, it is necessary to use a slightly tricky method to use it with the --require flag of node.js. check out following example:

const { waitUntilLoaded } = require('@handstudio/envman');

// Your App Entrypoint

(async () => {
  console.log('Waiting for envman ...');
  await waitUntilLoaded(); // waits until ENVMAN loading complete

  console.log('App started!');
  console.log(process.env); // At this moment, ENVMAN will be finished loading all environment variables.
})();

Function references

async fetchEnvironments(keys: string[])

Loads the environment variables from remote store. returns Promise<Environments>.

async storeEnvironments(key: string, envs: Environments)

Saves the environment variables to remote store.

async waitUntilLoaded()

Waits for environment variable loading to complete.

Roadmap

TBD