agentleFS
saizulsaizul/nodejs-backend-skills/skills/env-config/SKILL.md

env-config

Skill0 starsChanged 3 days agoMITView on GitHub

Environment configuration for Node.js backends - typed validation of process.env with zod at startup (fail fast, no default secrets, coerced numbers and booleans), one config module, .env hygiene (.gitignore, node --env-file, production secrets from the platform) and a checker that compares .env.example with what the code actually reads (process.env.X, destructuring, import.meta.env, configService.get, zod/envalid schema keys, Prisma env()). It reports undocumented and unused variables, real-looking secrets in .env.example, hard-coded secret fallbacks, required variables missing from .env, .env files not git-ignored and missing validation - never printing values. Use when the user adds or audits config, sees "undefined" config at runtime, onboards a developer, writes .env.example, or asks how to manage environment variables and secrets in Node.js.

  • Reads credentials

5 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Every variable the code reads is documented, validated once at startup and typed.

    line 13
  2. Distinctive:

    Fix drift: Add undocumented variables to the example (empty = required, value = local default, comment with the format).

    line 52
  3. Distinctive:

    Verify: run the checker again (expect no medium+), start the app with a variable removed and confirm it exits with a clear message naming …

    line 59

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Environment config

Every variable the code reads is documented, validated once at startup and typed; secrets never have defaults and never live in git.

Paths below are relative to this skill's folder (in Claude Code: ${CLAUDE_SKILL_DIR}).

When to use

  • "Check my .env.example", "which env vars does this app need?"
  • Config is undefined in production, a deploy fails because a variable is missing
  • Adding zod/envalid validation, centralising process.env access
  • Onboarding: generating a complete .env.example

When not to use

  • Secrets hard-coded in source (not env): node-security-review (secret.hardcoded)
  • Docker/systemd/PM2 environment wiring: node-deploy
  • Front-end-only env (Vite/Next public vars) beyond the basics

Workflow

  1. Find the files. Example file (.env.example, .env.sample), local .env, .gitignore, any existing config module (src/config*, env.ts).
  2. Inventory what the code reads.
    python3 scripts/env_check.py . --list
  3. Compare (read-only; values are never printed).
    python3 scripts/env_check.py .                               # uses ./.env.example and ./.gitignore
    python3 scripts/env_check.py src --example .env.example --gitignore .gitignore
    python3 scripts/env_check.py . --env .env --json             # also check the local .env
    python3 scripts/env_check.py . --allow RENDER_GIT_COMMIT     # platform-provided variable
    Exit 1 = findings at or above --fail-on (default medium).
  4. Handle urgent findings first.
    • env.file_not_ignored / env.example_secret: fix .gitignore now. If the file was ever committed or pushed (git log --all -- .env), tell the user to rotate every secret in it. Do not print or copy the values.
    • env.default_secret: remove the fallback; required secrets fail at startup.
  5. Fix drift. Add undocumented variables to the example (empty = required, value = local default, comment with the format); delete or explain unused ones.
  6. Centralise and validate (show the diff first): adapt assets/env.ts, import it as early as possible (src/server.ts first line or via the config module), replace process.env.X reads with env.X. Use assets/.env.example as the layout template. Rules and alternatives (envalid, NestJS ConfigModule, @fastify/env, node --env-file) in references/env-hygiene.md.
  7. Verify: run the checker again (expect no medium+), start the app with a variable removed and confirm it exits with a clear message naming the variable.

Output

env check: api - 1 high, 4 medium, 2 low
HIGH  .env is not git-ignored -> added '.env*' + '!.env.example'; was it ever committed? (git log --all -- .env)
MED   JWT_SECRET falls back to a literal in src/auth.ts:3 -> required in env.ts (min 32 chars)
MED   undocumented: SMTP_HOST, FEATURE_1..5 -> added to .env.example (diff below)
LOW   unused: OLD_FEATURE_FLAG -> removed
LOW   no validation -> src/config/env.ts added; 14 process.env reads replaced

Startup with DATABASE_URL unset:
Invalid environment configuration:
  DATABASE_URL: Required

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.