API Reference

@dotenvx/dotenvx

Drop-in replacement for dotenv with encrypted .env files, multi-environment support, and runtime injection.

Official Documentation ↗
CompatibilityThis documentation covers version v1.0. Check the official docs for the latest API surface.

Installation

npmnpm install @dotenvx/dotenvx

Methods

@dotenvx/dotenvx is drop-in replacement for dotenv with encrypted .env files, multi-environment support, and runtime injection. This page documents the core methods, installation, and common usage patterns for the current stable release.

Installation

Install @dotenvx/dotenvx with your preferred package manager using the command shown in the frontmatter. The package is published to the npm registry and ships with TypeScript types where applicable.

Core methods

The methods listed in the frontmatter cover the primary API surface. Each signature reflects the v1.0 release. Consult the official documentation linked in sourceUrl for advanced options, edge cases, and breaking changes between major versions.

Frequently asked questions

The faq section in the frontmatter answers the most common questions about @dotenvx/dotenvx, including comparisons with alternatives, configuration tips, and runtime requirements. If your question is not covered, check the source URL for the full guide.

Errors

The official API reference declares the following error types:

  • ALREADY_ENCRYPTED (encrypt –with 场景的失败错误码(官方 README)) — official text: “A different public key, or an encrypted: value without a matching declared public key, fails with ALREADY_ENCRYPTED and leaves the file unchanged.” (source: https://cdn.jsdelivr.net/gh/dotenvx/dotenvx@latest/README.md, fetched 2026-11-08T18:44:00+08:00)

Security

Official security statements captured from the package documentation:

API reference evidence

Fetched from official sources on 2026-11-08T18:44:00+08:00 via WebFetch https://cdn.jsdelivr.net/gh/dotenvx/dotenvx@latest/README.md;HTTP GET https://unpkg.com/@dotenvx/dotenvx@latest/src/lib/main.d.ts.

FAQ

How does encryption work?
Run dotenvx encrypt to generate an encrypted .env and a private key; decrypt at runtime with the key.
Is it backward compatible with dotenv?
Yes. The config function matches the dotenv API; swap the import.
Can I load multiple files?
Yes. Pass path: ['.env', '.env.local'] to load and merge in order.