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

@interval/envoy

v1.0.1

Published

Envoy gives your TypeScript apps type safe access to environment variables.

Downloads

6

Readme

🚛 Envoy

Envoy gives your TypeScript apps type safe access to environment variables.

How Envoy works

Envoy accepts an envoy.config.ts file and an .env file as input and generates a single env.ts file which exports a constant for each variable as output.

Envoy in action

There are a few major benefits to this approach:

  1. You no longer need to keep track of what environment variables + secrets your app needs to run. Your envoy.config.ts defines them all.
  2. By adding a envoy step before starting your app, you can prevent it from starting/deploying unless all required environment variables are present.
  3. Because envoy generates a .ts env file, you get full editor support and static type checking. Mistyping a variable name will result in a compile time error, not a mysterious runtime bug.

Getting Started

  1. Install Envoy

Using yarn:

yarn add @interval/envoy
  1. Create your config + .env files

You'll next need to create an Envoy config file. This defines the variables that Envoy will expect.

⚙️ envoy.config.ts

import { EnvoyVariableSpec } from '@interval/envoy'

const vars: EnvoyVariableSpec[] = ['DATABASE_URL', 'STRIPE_API_KEY']

export default vars

Commit this to your repo!

🔐 .env

This is a standard .env file in KEY=VALUE format. Each key in this file should correspond to what you've defined in envoy.config.ts.

The values in this file are either secrets which you can't commit or environment specific configuration details which you shouldn't.

DATABASE_URL=postgres://[email protected]:5432
STRIPE_API_KEY=sk_test_123456789101112131415

Don't commit this file!

  1. Run envoy!

Running yarn envoy will look for a .env and envoy.config.ts file in your current working directory and will output an env.ts file that looks like this:

// THIS FILE WAS AUTOMATICALLY GENERATED BY ENVOY
// TO ADD A NEW ENVIRONMENT VARIABLE, RUN ENVOY
// DO NOT EDIT THIS FILE DIRECTLY

const DATABASE_URL = 'postgres://[email protected]:5432'
const STRIPE_KEY = 'sk_test_123456789101112131415'

export { STRIPE_KEY, DATABASE_URL }

You can use this like any other TypeScript file. Just be sure that you don't commit this file as it contains your secrets that you defined manually in your .env file.

Behavior

If you define a variable in .env but exclude it from your envoy.config.ts, the resulting env.ts file will not contain that variable.

If you define a variable in envoy.config.ts, but don't define it in your .env, Envoy will fail and will exit with code 1.

Recommended usage

We suggest you run yarn envoy each time your app compiles. For example, at Interval, our yarn start:dev command runs yarn envoy && yarn ts:node.

Note that this library effectively hard codes your secrets into each build. Depending on your infrastructure, this may be a non-starter.