npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

de-env

v1.1.6

Published

A command-line tool for managing environment variables

Readme

npm GitHub stars

de-env

A simple and efficient environment variable parser that generates TypeScript/JavaScript files from your environment variables using a schema-based approach.

Visit our official website: de-env.v1noid.com

What it does

de-env takes your environment variables and converts them into a strongly-typed TypeScript/JavaScript module using a schema definition. It helps your project validate environment variables in two ways:

  1. Manual Schema Definition: Define your environment variable types and requirements explicitly
  2. Automatic Schema Generation: Use de-env <env-path> <output-path> command to automatically generate a schema from your .env file

Key Features

  • Generates a schema from your environment variables
  • Handles type casting (string, number, boolean)
  • Supports optional fields validation using #! prefix in .env
  • Supports different module formats (ESM/CommonJS)
  • Automatic TypeScript type generation for better debugging

Example

Given environment variables:

# Database configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=mydb
#!
API_KEY="your-secret-key"  # Using #! marks this as optional
DEBUG=true

You can also use optional block

# starting of optional block with #!!!
#!!!
DB_HOST=localhost
DB_PORT=5432
DB_NAME=mydb
API_KEY="your-secret-key"
DEBUG=true
#---
# use #--- to end the block

Now all the variable in between the comment are marked as optional

import { EnvSchema } from "de-env";

export const Env = EnvSchema({
  DB_HOST: ["string", "optional"],
  DB_PORT: ["number", "optional"],
  DB_NAME: ["string", "optional"],
  API_KEY: ["string", "optional"],
  DEBUG: ["string", "optional"]
});

Automatic Schema Generation

Running de-env .env config.env.ts will automatically generate:

// config.env.ts
import { EnvSchema } from "de-env";

export const Env = EnvSchema({
  DB_HOST: "string",
  DB_PORT: "number",
  DB_NAME: "string",
  API_KEY: ["string", "optional"], // Automatically marked as optional due to #!
  DEBUG: "boolean"
});

Manual Schema Definition

You can also manually define your schema:

// config.env.ts
import { EnvSchema } from "de-env";

export const Env = EnvSchema({
  DB_HOST: "string",
  DB_PORT: "number",
  DB_NAME: ["string", "optional"], // Mark as optional
  API_KEY: ["string", "optional"], // Mark as optional
  DEBUG: "boolean"
});

Now you can use your environment variables with full TypeScript support:

import Env from './config';

// TypeScript will provide autocomplete and type checking
console.log(Env("DB_HOST" /* Because of typescript
you will get the keys suggestion here */));    // Type: string
console.log(Env("DB_PORT"));    // Type: number
console.log(Env("API_KEY"));    // Type: string
console.log(Env("DEBUG"));      // Type: boolean

// Will throw an error if DB_NAME is not set in environment variables
console.log(Env("DB_NAME"));    // Type: string

Installation

npm install de-env

Usage

Automatic Schema Generation

Using cli tool to generate

de-env <env-path> <output-path>

Schema Types

The schema supports the following types:

  • "string" - String values
  • "number" - Numeric values (automatically converted)
  • "boolean" - Boolean values (automatically converted)

You can mark fields as optional in two ways:

  1. Using #! prefix in your .env file:
#!
optional_VAR=value
  1. Using an array with "optional" in your schema:
{
  optional_FIELD: ["string", "optional"],
  OPTIONAL_FIELD: "string"
}

Features

  • Automatic schema generation from environment variables using de-env
  • Manual schema definition for fine-grained control
  • Automatic type casting based on schema
  • optional field validation (using #! or schema definition)
  • TypeScript support with full type inference
  • Automatic type generation for better debugging

Workflow

  1. Set up your environment variables (use #! prefix for optional variables)
  2. Run de-env config.ts to automatically generate the schema or manually write schema
  3. Use the Env function in your code with full type safety

License

MIT