Socket
Book a DemoInstallSign in
Socket

typed-env

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-env

Typed environment variable parser

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
7.7K
0.49%
Maintainers
2
Weekly downloads
 
Created
Source

typed-env

npm version monthly downloads

A typed environment variable parser with support for choices, custom parsers, and more.

Usage

import { createEnv } from 'typed-env';

const env = createEnv({
  PORT: { type: 'number', default: 80 }
});

env.PORT; // number

Features

  • Strongly typed
  • Supports custom parsers
  • Supports optional environment variables
  • Supports limiting the possible values (see Choices)
  • Supports passing custom environments (see Options)

Choices

import { createEnv } from 'typed-env';

const env = createEnv({
  NODE_ENV: {
    type: 'string',
    choices: ['development', 'production']
  }
});

env.NODE_ENV; // 'development' | 'production'

Parser

You can pass a parser function to return your own custom type

import { createEnv } from 'typed-env';

const env = createEnv({
  HOMEPAGE: { parser: url => new URL(url) }
});

env.HOMEPAGE; // URL

Options

If you want to use a custom env, pass env in the options parameter, otherwise it will load from process.env

interface Options {
  env?: Record<string, string> | NodeJS.ProcessEnv;
}

Keywords

environment variables

FAQs

Package last updated on 25 May 2025

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.