Socket
Book a DemoInstallSign in
Socket

env-native

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

env-native

Minimalistic, dependency-free .env loader using Node.js's native util.parseEnv. Much faster than dotenv, with CLI support.

1.1.3
latest
Source
npmnpm
Version published
Weekly downloads
109
1716.67%
Maintainers
1
Weekly downloads
ย 
Created
Source

๐Ÿ“„ env-native

Minimalistic, zero-dependency .env loader using Node.js's native util.parseEnv. Significantly faster and smaller than dotenv and dotenvx. If you like this module, please star the repository on GitHub. Thanks for your support!

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

โš ๏ธ Good to know

Since v20.12.0, Node.js includes built-in process.loadEnvFile and util.parseEnv.
If you don't need env-native's CLI, stick with the built-in Node.js functions.

process.loadEnvFile(); // It will immediately load your .env file into process.env

Example with parseEnv:

const { parseEnv } = require('node:util');
parseEnv('HELLO=keyboard cat');// Returns: { HELLO: 'keyboard cat' }

๐Ÿš€ Features

  • Zero dependencies
  • Fast and lightweight (~14 KB)
  • Uses built-in util.parseEnv
  • Simple API: config(options) or parse(content, options)
  • Supports custom file paths and variable overrides
  • Supports CLI
  • ESM and CJS support
  • 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)

ModuleSizeWorkstation (ms)Thin Client (ms)
env-native (ESM)~ 14 KB0.79, 0.78, 0.78, 0.762.55, 2.97, 2.74, 2.51
dotenv (CJS)~ 79 KB7.71, 8.06, 8.1, 8.6137.40, 40.96, 37.91, 35.93
dotenvx (CJS)~ 293 KB91.82, 97.76, 96.76, 99.50286.74, 270.07, 269.07, 278.70

env-native is fast, clean, and native โ€” with no logs, no overhead, and up to 90ร— faster than dotenvx on low-end 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 24H2

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! https://youtu.be/J---aiyznGQ"

process.js

import { config } from 'env-native';
config(); // require('env-native').config(); for CJS

console.log(process.env.HELLO_WORLD); // Keyboard cat! https://youtu.be/J---aiyznGQ

๐Ÿงฉ API

config(options?)

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

Parameters

OptionTypeDefaultDescription
pathstring.envPath to your .env file
encodingstringutf8File encoding
overridebooleanfalseOverwrite 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

OptionTypeDefaultDescription
coercebooleantrueAutomatically converts values: "false" โ†’ false, "42" โ†’ 42, etc.
freezebooleantrueFreeze 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);

๐Ÿ–ฅ๏ธ CLI Usage

env-native [--env <file>] [--coerce|--no-coerce] [--freeze|--no-freeze] [--cmd <command> [args...]]
enative [--env <file>] [--coerce|--no-coerce] [--freeze|--no-freeze]

The CLI is available as both env-native and enative (alias).

Options

FlagAliasDefaultDescription
--env <file>-e.envPath to .env file
--cmd <command>-cโ€“Command to execute with loaded environment
--coercetrueAuto-convert numbers and booleans
--no-coerceโ€“Disable auto-convert
--freezetrueFreeze parsed object
--no-freezeโ€“Disable freezing
--help-hโ€“Show help message
--version-vโ€“Print version

Examples

env-native --env .env
env-native --env .env --no-coerce --no-freeze
env-native --env .env --cmd node app.js
env-native -e .env -c node app.js

๐Ÿ”’ License

Copyright ยฉ Sefinek. Licensed under the MIT License.

Keywords

env

FAQs

Package last updated on 02 Sep 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.