Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

envExampleMaker

A small Node.js CLI that scans your codebase for process.env and import.meta.env usage and generates a .env.example file with all discovered variables.

Features

  • Multi-runtime: Detects both process.env.VAR_NAME (Node) and import.meta.env.VAR_NAME (Vite, etc.)
  • Multiple languages: Scans .js, .ts, .jsx, .tsx, .mjs, .cjs, .vue, .svelte
  • Sensible ignores: Skips node_modules, .git, dist, build, .next, and other common output/cache dirs
  • Report + file: Prints a report of variables and where they’re used, then writes .env.example
  • Non-destructive: If a .env exists, the script only notes that values exist; it does not overwrite .env

Requirements

  • Node.js 14+ (uses only built-in fs and path; no dependencies)

Usage

# Scan current directory and generate .env.example
node index.js

# Scan a specific directory
node index.js /path/to/your/project

Or make it executable and run directly:

chmod +x index.js
./index.js
./index.js /path/to/project

Output

  1. Console: A list of unique env variable names and the files/lines where they appear.
  2. File: A new or updated .env.example in the target directory with:
    • One entry per variable as VAR_NAME=
    • Comments indicating which files use each variable

Example

Given code that uses process.env.API_URL and import.meta.env.VITE_APP_KEY, running:

node index.js .

produces a report like:

🔍 Scanning: /path/to/project

Found 2 unique env variables across 5 files:
────────────────────────────────────────────────────────────

  API_URL
    → src/api.js:12
  VITE_APP_KEY
    → src/config.ts:3

────────────────────────────────────────────────────────────

Generated .env.example with 2 variables
   /path/to/project/.env.example

And a .env.example similar to:

# ============================================
# Environment Variables
# Auto-generated by scan-env.js on 2025-02-14
# ============================================

# Used in: src/api.js
API_URL=

# Used in: src/config.ts
VITE_APP_KEY=

Ignored directories

The scanner skips: node_modules, .git, dist, build, .next, .nuxt, coverage, .turbo, .cache.

License

Use and modify as you like.

About

This is a node script that will scan a project and pull all of the examples into an env.example file.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages