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

envtk

v2.0.10

Published

CLI tool to asynchronously set environment variables before building a project.

Downloads

75

Readme

envtk

header

npm npm oclif GitHub Workflow Status (with event) GitHub license

Features

  • run commands with preloaded environment variables from a javascript file (supports async)
  • run commands with preloaded environment variables from an existing .env file
  • output the resulting environment variables as JSON for integration with other scripting languages

Installation

Currently there are 2 ways of installing envtk

NPM

envtk can be installed via npm:

  $ npm install -g envtk

Binaries

Binaries for each OS can be downloaded from the releases page

Refer to the installation docs for each OS on how to install envtk.

Quickstart

  1. Create a javascript file (we'll call it myScript.js) and default export a function that returns an object:
  1. (optional) Create a .env file with defaults to include, lets call it defaults.env:
  1. run the envtk run command and reference the files created above, we will execute the printenv command to see all current environment variables:
  $ npx envtk run printenv -s myScript.js -e defaults.env

will result in the following output:

MY_ENV_VAR=abc123
SECRET=SomethingFromAnApi
MY_AWS_SECRET_NAME=myAppSecret
DEFAULT_ENV_VAR=someDefaultThing

Note: we see the result printed because we ran printenv. If we had let's say a project that started with npm run dev and we passed that as command (so envtk run "npm run dev" -s myScript.js -e defaults.env, that project would now have access to the above environment variables via process.env

Table of contents

Motives

I noticed that a lot of populair frameworks, infrastructure tooling or other 3rd party services make use of environment variables or .env files but provide no way to load them from a 3rd pary secret manager (for example AWS Secrets Manager).

While tooling like dotenv-vault provides alot of functionality for safely managing secrets/environment variables, not everyone uses or can use dotenv-vault. This project aims to be a simple alternative tool for retrieving your secrets from wherever: a 3rd pary API, encrypted database, whatever and then passing those variables to the next step in your startup/deploy pipeline.

Usage

$ npm install -g envtk
$ envtk COMMAND
running command...
$ envtk (--version)
envtk/2.0.10 linux-x64 node-v18.20.1
$ envtk --help [COMMAND]
USAGE
  $ envtk COMMAND
...

Commands

envtk create OUTPUT

create a .env file using env vars loaded from a script or existing .env files

USAGE
  $ envtk create OUTPUT [--json] [-s <value>] [-e <value>]

ARGUMENTS
  OUTPUT  path for the output file

FLAGS
  -e, --envFile=<value>  path to .env file with defaults to include
  -s, --script=<value>   path to .(mjs|js) script.

GLOBAL FLAGS
  --json  Format output as json.

DESCRIPTION
  create a .env file using env vars loaded from a script or existing .env files

EXAMPLES
  Create .env file with env variables returned from script

    $ envtk create ".env" -s ./load-env.js

  Create .env file with env variables returned from script and include defaults from ".defaults.env"

    $ envtk create ".env" -s ./load-env.js -e .defaults.env

See code: src/commands/create.ts

envtk help [COMMANDS]

Display help for envtk.

USAGE
  $ envtk help [COMMANDS] [-n]

ARGUMENTS
  COMMANDS  Command to show help for.

FLAGS
  -n, --nested-commands  Include all nested commands in the output.

DESCRIPTION
  Display help for envtk.

See code: @oclif/plugin-help

envtk run COMMAND

run a given command with loaded env variables

USAGE
  $ envtk run COMMAND [--json] [-s <value>] [-e <value>]

ARGUMENTS
  COMMAND  command to run with the loaded environment variables

FLAGS
  -e, --envFile=<value>  path to .env file with defaults to include
  -s, --script=<value>   path to .(mjs|js) script.

GLOBAL FLAGS
  --json  Format output as json.

DESCRIPTION
  run a given command with loaded env variables

EXAMPLES
  Run command with env variables returned from script

    $ envtk run "npm run dev" -s ./load-env.js

  Run command with env variables returned from script and include defaults from ".env"

    $ envtk run "npm run dev" -s ./load-env.js -e .env

See code: src/commands/run.ts