NIAOJoin Beta
Ecosystem

nenv

available

Environment Variables

Core Standard Library

Overview

nenv handles configuration from the environment. Call load(".env") at startup to merge a dotenv file into the process env, then read values with get_string, get_int, get_bool, and friends, each with a default if the key is missing.

Declare a schema of required keys and types and fail fast on boot if something's wrong, instead of crashing mid-request. For tests, spin up an isolated in-memory store so cases don't leak env vars into each other.

  • .env loading
  • Typed getters
  • Schema validation
  • Test isolation

Import

import
import "nenv"

Quick start

quick start
import "nenv"
nenv.load(".env")
let port = nenv.get_int("PORT", 8080)
let debug = nenv.get_bool("DEBUG", false)

Capabilities

High-level overview of what nenv is for.

.env loading

Parse KEY=VALUE lines from a file and overlay them onto the process environment.

Typed getters

get_int, get_bool, get_float with defaults, no manual parseInt and no silent string "false" truthiness bugs.

Schema validation

List required keys and expected types; the app refuses to start if config is incomplete.

Isolated stores

In-memory env for unit tests that doesn't touch the real process environment.

API reference

27 functions and methods in nenv. Grouped by category from the standard library docs.

Loading `.env` files

SignatureDescription
nenv.load(path?, opts?)Load one file (default `.env` in cwd). `opts`: `{override: bool}` (default `false`). Returns `int` count applied or `error`.
nenv.load_many(paths, opts?)Load files in order; later keys apply when `override: true` or key not yet set.
nenv.load_defaults(opts?)Load `.env` then `.env.local` if they exist.
nenv.parse(path)Parse file without mutating process env; returns `{KEY: "value", ...}`.
nenv.parse_text(text)Parse string content without applying.
nenv.find_up(filename?, start_dir?)Walk parent directories for a file (default `.env`); returns path or `nil`.

Process environment

SignatureDescription
nenv.get(key)Read process env; `nil` or default if missing.
nenv.get(key, default)Read process env; `nil` or default if missing.
nenv.set(key, value)Mutate process env.
nenv.unset(key)Mutate process env.
nenv.has(key)`bool` - key exists.
nenv.all()Snapshot of all process variables as an object.
nenv.require(key)Returns string or `error` if missing.
nenv.get_int(key, default?)Parse integer.
nenv.get_bool(key, default?)Accept `true/false/1/0/yes/no/on/off`.
nenv.get_float(key, default?)Parse float.
nenv.expand(text)Expand `$VAR` and `${VAR}` using process env.
nenv.validate(schema)`schema`: `{required: [...], types: {KEY: "int"

Isolated stores

SignatureDescription
nenv.open(opts?)New store handle (`int`). `opts`: `{inherit: bool}` - seed from current process env.
nenv.close(store)Release handle.
nenv.from_object(map)Build store from `{KEY: value}` object.
nenv.store_load(store, path, opts?)Parse file into store only.
nenv.store_get(store, key, default?)Read from store (plus inherit layer if configured).
nenv.store_set(store, key, value)Set in store.
nenv.store_unset(store, key)Remove from store.
nenv.store_all(store)Merged object view.
nenv.store_apply(store, opts?)Push store vars into process env.

Related libraries

More from Core Standard Library.

available

json

JSON Parse & Manipulate

Parse, build, and edit JSON. Backed by serde_json in Rust, nested get/set, merge, and pretty-print included.

  • parse & stringify
  • Dot-path access
  • Deep merge
  • Pretty-print
Read more
available

io

File & Path I/O

Read and write files, stream large inputs, and work with paths. Blocking I/O can run on background threads.

  • Whole-file read/write
  • Streaming handles
  • Background I/O
  • Path helpers
Read more
available

time

Wall-Clock & Time Zones

Timestamps, formatting, parsing, and time zones. Built on chrono and chrono-tz, DST handled correctly.

  • IANA time zones
  • strftime formats
  • Datetime values
  • Date math
Read more