Socket
Book a DemoInstallSign in
Socket

@echristian/env

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

@echristian/env

Small, cross runtime utility function to get environment variables.

npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

@ericc/env

A simple wrapper around std-env, re-exporting all its functionality while providing a convenient interface for environment variable handling.

Installation

npm i @echristian/env
deno add jsr:@ericc/env

Why?

This package serves as a wrapper around std-env, re-exporting all of its functionality while also providing a simplified interface for common environment variable operations:

  • Throw when required environment variable does not exist
  • Fallback to default value for optional variable
  • Avoid repeatedly writing optional chaining and error throwing (with this the value won't be Value | undefined)

Usage

import { getEnv, env } from "@ericc/env";

// Using getEnv helper
const API_KEY = getEnv("API_KEY"); // throws if not found
const IMAGE_DIR = getEnv("IMAGE_DIR", "/tmp"); // with fallback

// Direct access to std-env exports
console.log(env.NODE_ENV);
console.log(env.platform);

Check out std-env because unjs is awesome.

FAQs

Package last updated on 26 Nov 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