New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@tnezdev/env

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tnezdev/env

A wrapper to make dealing with environment variables less painful

Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@tnezdev/env

A wrapper to make dealing with environment variables less painful.

Installation

  • npm: npm install @tnezdev/env
  • yarn: yarn add @tnezdev/env
  • pnpm: pnpm add @tnezdev/env

Usage

Require this in any file where you need to reference an environment variable. It will throw if the expected key is not defined, otherwise it will return a string.

import { getEnv } from "@tnezdev/env";
import SomeClient from "./clients/some-client";

const configureDefaultClient = () =>
  new SomeClient({
    username: getEnv("SOME_CLIENT_USERNAME"),
    password: getEnv("SOME_CLIENT_PASSWORD"),
  });

export default function (client = configureDefaultClient()) {
  // ... do something cool ...
}

You can also provide a default value to use if the key is not defined in process.env:

getEnv("BASE_URL", { default: "http://localhost:3000" });

Keywords

environment

FAQs

Package last updated on 24 Feb 2023

Related posts