@ahoylabs/env-ts
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

@ahoylabs/env-ts

env-ts is a tool to manage and type check environment variables (unlike .env).

It's written in TypeScript and designed for monorepo setups (like Turborepo).

It generates code to make sure that environment variables that your app needs are never undefined.

Install

# add the package
yarn add --dev @ahoylabs/env-ts
# init the tool
yarn env-ts init

Usage

In package.json

Usages: env-ts [env-file-name] [app-name] [optional-filter-for-env-names] && env $(env-ts [env-file-name] [app-name]) [command]

For example, in repos/app/package.json:

{
  "scripts": {
    // check the `env.ts` file's sub-repo `app` for valid env vars,
    // creating a generated `_env.ts` only for vars that start with `NEXT_PUBLIC_`
    "check-env": "env-ts env.ts app NEXT_PUBLIC_",
    // check then inject the
    "start": "yarn check-env && env $(env-ts env.ts app) next dev"
  }
}

In Your App

// first import the auto-generated env object
import { env } from './__generated__/env.ts`

// now you have the fully typed env vars
console.log(env.EXAMPLE_ENV)

License

MIT © Ahoy Labs, Inc.

Readme

Keywords

none

Package Sidebar

Install

npm i @ahoylabs/env-ts

Weekly Downloads

0

Version

0.3.1

License

MIT

Unpacked Size

11.1 kB

Total Files

9

Last publish

Collaborators

  • 719ben