godotenv

A Go port of Ruby's dotenv that loads environment variables from .env files into your process, with zero third-party dependencies.

Library
Go
vv1.5.1
10,667 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
50 /100 Fair
Development Activity 20
Maintenance 20
Community 60
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
73 /100 Good
Architecture 72
Code Quality 85
Innovation 88
Learning Curve 45

godotenv is a small, dependency-free Go library that ports Ruby’s dotenv to the Go ecosystem, reading key-value pairs from a .env file and loading them into the process environment so twelve-factor apps can keep configuration and secrets out of source control. It exposes both a mutating API (Load, Overload) for wiring env vars into os.Getenv and a pure API (Read, Parse, Unmarshal) for callers who want a plain map[string]string instead, plus Write/Marshal for serializing a map back to .env format.

Beyond the library, the module ships an autoload subpackage for zero-code side-effect loading and a standalone godotenv CLI (cmd/godotenv) that runs another command with an env file preloaded. The parser supports comments, quoted values, variable expansion (${VAR}), export prefixes, and YAML-style key: value syntax, and the project has explicitly declared itself feature-complete, focusing further contributions on compatibility fixes and bug fixes rather than new functionality.

What You Get

  • A one-line godotenv.Load() call that reads .env from the working directory into os.Getenv
  • Non-destructive Load/Read and destructive Overload variants for controlling whether existing env vars are preserved or replaced
  • Pure functions (Parse, Unmarshal, UnmarshalBytes) that return a map[string]string instead of mutating global state, for callers who want isolation
  • Write/Marshal helpers to serialize a map[string]string back into a correctly quoted and escaped .env file
  • An autoload subpackage for import-only side-effect loading (import _ "github.com/joho/godotenv/autoload")
  • A standalone godotenv CLI binary that runs an arbitrary command with env vars preloaded from one or more files

Common Use Cases

  • Loading local development secrets (API keys, DB URLs) from a .env file that’s excluded from version control
  • Bootstrapping environment-specific configuration by chaining .env, .env.{ENV}, and .env.local loads in a defined precedence order
  • Running a process with an injected environment via the CLI without modifying shell profile or CI job configuration
  • Reading env vars into an isolated map (via Read/Parse) for testing or for merging with other config sources instead of mutating the real process environment

Under The Hood

Architecture

The module is a flat, single-purpose Go package: godotenv.go exposes the public API (Load, Overload, Read, Parse, Unmarshal, Write, Exec), while parser.go isolates the actual parsing logic (parseBytes, getStatementStart, locateKeyName, extractVarValue) behind that surface. There’s no dependency injection or interface abstraction — it’s straightforward procedural Go built around a byte-slice “cutset” technique, where each parse step consumes a prefix of the remaining bytes and returns what’s left, avoiding per-line allocations. Two satellite packages extend the core without touching it: autoload wraps Load() in an init() for side-effect-only imports, and cmd/godotenv is a thin CLI wrapping Exec(). Because every public entry point (Parse, Unmarshal, UnmarshalBytes, file loading) ultimately funnels through parseBytes, that function is the single point where a change would ripple across the entire public API.

Tech Stack

Zero third-party runtime dependencies — the entire library is built on the Go standard library (bytes, os, os/exec, regexp, sort, strings, unicode, errors), targeting go 1.13 per go.mod. The CLI uses the stdlib flag package rather than a third-party CLI framework. Tooling is plain go build/go install; CI runs standard go test/vet plus a CodeQL security scan, and Dependabot keeps GitHub Actions versions current. Distribution is purely as an importable module (and an installable CLI via go install), with no runtime services or external integrations.

Code Quality

The test file is substantially larger than the combined source it covers, and is driven by dedicated fixture .env files exercising comments, quoting, exports, variable substitution, hyphenated keys, and deliberately invalid syntax. Parse failures return typed sentinel errors (ErrZeroLengthString, ErrUnexpectedChar, ErrUnterminatedQuote) wrapped with fmt.Errorf("%w ...") rather than being swallowed or panicking. Naming follows idiomatic Go conventions throughout (exported PascalCase API, unexported camelCase internals), and CI plus CodeQL static analysis run on every change. No dedicated linter config file was found, but the codebase is small enough that this has limited practical impact.

API Design The public surface favors minimal boilerplate: godotenv.Load() with no arguments loads .env from the current directory in one line, matching the ergonomics of Ruby’s and Node’s dotenv equivalents. Verb naming is consistent and orthogonal rather than one overloaded function with flags — Load/Overload mutate process env, Read/Parse/Unmarshal/UnmarshalBytes return a plain map without side effects, and Write/Marshal invert the process for serialization. Every exported symbol carries a godoc comment with a runnable usage snippet, and the autoload subpackage reduces the common case to a single blank import with zero application code required.

Used by 27 apps in this directory

TypeScript
53%
MIT

MentraOS

AI Development · Developer Tools

2,391

The open source operating system and SDK that lets developers build one app and run it across smart glasses from Even Realities, Vuzix, Mentra Live, and more.

View details
92
Repo Health
77
Technical
66
Dependency
Built with
TypeScript 53%
Java 16%
Updated 6 days ago
TypeScript
82%
AGPL 3.0

OpenStatus

Devops · Monitoring

9,221

Open-source status pages and uptime monitoring with global synthetic checks, monitoring-as-code, and AI agent integration via MCP.

View details
77
Repo Health
82
Technical
69
Dependency
Built with
TypeScript 82%
MDX 14%
Updated 1 weeks ago
TypeScript
54%
Other

OpenReplay

Analytics

13,042

Self-hosted session replay and product analytics suite that lets you see exactly what users do on your web app — without sending data to third parties.

View details
91
Repo Health
77
Technical
66
Dependency
Built with
TypeScript 54%
Go 13%
Updated 1 weeks ago
Go
82%
AGPL 3.0

PeerDB

Data Engineering · Databases

3,309

Postgres-native ETL that streams change data capture in real time to Snowflake, BigQuery, ClickHouse, S3, and Kafka — up to 10x faster than general-purpose pipelines, managed through a familiar Postgres SQL interface.

View details
89
Repo Health
76
Technical
66
Dependency
Built with
Go 82%
TypeScript 12%
Updated 6 days ago
TypeScript
51%
ZLIB

Portainer

Devops

38,707

A lightweight, open-source web UI that puts Docker, Kubernetes, and Podman management within reach of any team—no CLI expertise required.

View details
93
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 51%
Go 38%
Updated 1 weeks ago
Go
82%
Other

PrivateCaptcha

Authentication · Security

198

Privacy-first, self-hostable Proof-of-Work CAPTCHA for GDPR-compliant bot protection.

View details
74
Repo Health
78
Technical
74
Dependency
Built with
Go 82%
HTML 10%
Updated 6 days ago
Go
40%
Apache 2.0

Rill

Analytics · Data Engineering

2,962

The fastest BI tool for humans and agents — define metrics, models, and dashboards as code and query them instantly on ClickHouse or DuckDB.

View details
88
Repo Health
88
Technical
64
Dependency
Built with
Go 40%
TypeScript 38%
Svelte 21%
Updated 6 days ago
Go
66%
GPL 3.0

Stormkit

Devops · Hosting Control Panel

264

Self-hostable platform for deploying and hosting modern web apps with automated CI/CD, custom domains, and a built-in serverless runtime — a true open-source alternative to Vercel and Netlify.

View details
80
Repo Health
79
Technical
67
Dependency
Built with
Go 66%
TypeScript 31%
Updated 1 weeks ago
Rust
71%
MIT

Trieve

AI Development · Developer Tools · Search

2,721

All-in-one self-hostable platform for hybrid search, RAG, recommendations, and analytics built on Rust and Qdrant.

View details
42
Repo Health
74
Technical
65
Dependency
Built with
Rust 71%
Updated 9 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers