env-native
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

📄 env-native

Minimalistic, zero-dependency .env loader powered by Node.js's native util.parseEnv. Significantly faster and smaller than dotenv and dotenvx. Designed for performance-critical, production-grade use cases in demanding environments.

npm version npm downloads Install size Minified size Build status Node.js version License MIT

🚀 Features

  • Zero dependencies
  • Fast and lightweight
  • Just 8 KB in size
  • Uses built-in util.parseEnv
  • Simple API: config(options) or parse(content, options)
  • Supports custom file paths and variable overrides
  • Supports both ESM and CJS
  • No self-promotion or console spam, unlike dotenv
  • Requires Node.js ≥ 20.12.0

📦 Installation

npm

npm install env-native

yarn

yarn add env-native

Make sure you're using Node.js version 20.12.0 or newer.

🧪 Benchmark (Node.js v22.17.0)

Module Package Size Workstation (ms) Thin Client (ms)
env-native (ESM) ~ 9 KB 0.793, 0.789, 0.782, 0.766 2.552, 2.971, 2.743, 2.516
dotenv (CJS) ~ 79 KB 7.712, 8.067, 8.1, 8.613 37.409, 40.966, 37.919, 35.935
dotenvx (CJS) ~ 293 KB 71.363, 71.766, 70.93, 70.828 252.899, 248.658, 249.393, 269.038

env-native is fast, clean, and native — with no logs, no overhead, and up to 90× faster than dotenvx on weaker systems. dotenvx is maintained by the same author as dotenv.

Test Environment

Workstation

  • CPU: AMD Ryzen 9 7945HX
  • Disk: KINGSTON SKC3000S1024G (NVM Express 1.4)
  • OS: Windows 11 Home

Thin Client

  • CPU: AMD GX-420GI
  • Disk: WD Red WDS500G1R0B (M.2 SATA)
  • OS: Ubuntu 24.04.2 LTS (Linux 6.8.0-63-generic)

🧪 Example

.env

HELLO_WORLD="Keyboard cat memes make your day better! https://youtu.be/J---aiyznGQ"

process.js

require('env-native').config();
console.log(process.env.HELLO_WORLD); // Keyboard cat memes make your day better! https://youtu.be/J---aiyznGQ

🧩 API

config(options?)

Loads a .env file and injects its variables into process.env.

Parameters

Option Type Default Description
path string .env Path to your .env file
encoding string utf8 File encoding
override boolean false Overwrite existing process.env variables

Note: All injected variables are always stored as strings in process.env.

Returns

void

Example with options

require('env-native').config({ path: './config/.env', override: true });

parse(content: string, options?)

Parses raw .env file content using the native util.parseEnv. Does not inject anything into process.env.

Parameters

Option Type Default Description
coerce boolean true Automatically converts values: "false"false, "42"42, etc.
freeze boolean true Freeze returned object (immutable)

Returns

Record<string, string | number | boolean>

Example

const { readFileSync } = require('node:fs');
const { parse } = require('env-native');

const raw = readFileSync('./config/.my-env-file', 'utf8');
const parsed = parse(raw, { coerce: true, freeze: true });

console.log(parsed);

🔒 License

Copyright 2025 © by Sefinek. All rights reserved.

Package Sidebar

Install

npm i env-native

Weekly Downloads

136

Version

1.0.2

License

MIT

Unpacked Size

9.61 kB

Total Files

4

Last publish

Collaborators

  • sefinek