New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@bb-tools/withenv

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bb-tools/withenv

An environment variable loader for your monorepo.

latest
Source
npmnpm
Version
0.2.1
Version published
Weekly downloads
3
200%
Maintainers
0
Weekly downloads
 
Created
Source

@bb-tools/withenv

This projects aims to simplify loading of environment variables with dotenv in a monorepo.

It consists of 2 parts:

  • A withenv command which we use to call dotenv before running commands.
  • A loadEnv function which you can reuse in any TS/JS code.

See the Configuration section for details about the .env.yaml file or continue reading for usage instructions.

Installation

npm install @bb-tools/withenv

Usage

withenv

Usage:

withenv <env> -- [command...]

Example:

withenv test -- jest

loadEnv

Usage:

import { loadEnv } from "withenv";

// Loads the environment into process.env
await loadEnv("test");

Configuration

Most of the magic behind withenv is a .env.yaml file whose goal is to define execution environments in a declarative way.

Example:

dev:
  nodeEnv: development
  files:
    - .env.dev

In this file, an environment named dev is declared.

As you might have guessed, when used with the dev environment, withenv will:

  • Set the NODE_ENV environment variable value to development.

  • Load non-sensitive environment variables from the .env.dev dotenv file located alongside the .env.yaml file.

  • Load local overrides and secrets from the .env.dev.local dotenv file.

Environment options

The properties described in the table below can be used for each environment defined in the .env.yaml file.

NameDescriptionRequiredDefault value
nodeEnvThe value of NODE_ENV to useNOEnvironment name if it exists in the NodeEnv enum of @kwentapay/node-utils package.
filesList of .env files to be loaded.YES
aliasAn optional alias to name the environment (e.g. development instead of dev)NO

Local overrides

Local files can be defined for both the dotenv and withenv:

  • <environment_file>.local (e.g. .env.local) to define local environment variables.

  • .env.local.yaml to add new environments or override the existing ones.
    i.e.: This is where your personal secrets can be placed.

These files must be ignored by Git (documentation). For example, you can add the following lines to your .gitignore file:

*.local
*.local.yaml

More information

See:

Keywords

dotenv

FAQs

Package last updated on 30 Jul 2024

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