Socket
Book a DemoInstallSign in
Socket

env-assert

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

env-assert

verify that environment variables exist before doing something

latest
npmnpm
Version
1.1.0
Version published
Weekly downloads
1.7K
15.07%
Maintainers
1
Weekly downloads
 
Created
Source

env-assert

Setup (after install):

npx env-assert
yarn env-assert
pnpm env-assert

This will create an example config file

env-assert.config.ts

Here you can setup your required and optional environment variables

import type { CreateEnvVarsType } from "env-assert";

const required = ["FOO"] as const;
const optional = ["BAR"] as const;

const config = {
  required,
  optional,
};

export default config;

export type EnvVars = CreateEnvVarsType<typeof config>;

How to use

Run env-assert before any script, for example:

yarn env-assert && yarn build

CleanShot 2022-11-27 at 8 28 20

Pass the type of your config to CreateEnvVarsType to receive a type that you can use to extend ProcessEnv, so you know what variables are available. 👌 CleanShot 2022-11-27 at 8 23 12

global.d.ts

import { EnvVars } from "./env-assert.config";

export declare global {
  declare namespace NodeJS {
    interface ProcessEnv extends EnvVars {}
  }
}

Keywords

env

FAQs

Package last updated on 29 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.