Easily create .env files and keep them in sync with the environment variables referenced in your codebase.
This tool scans supported source files for process.env.* (or import.meta.env.*) references,
then creates/appends entries in the environment templates Next.js and Vercel load.
This project now only targets the env files that Next.js and Vercel workflows use:
.env.env.local.env.development.env.development.local.env.test.env.test.local.env.production.env.production.local
The following conventions match current docs:
- local overrides are loaded from
.env.local(except in test environments) - environment-specific defaults come from
.env.$(NODE_ENV) - environment-specific secrets come from
.env.$(NODE_ENV).local - test mode uses
.env.testand.env.test.local
Install with npm:
npm install -g vercel-env-createOr run with npx:
npx vercel-env-createFrom a project root, run:
vercel-env-createThe tool:
- scans supported files under the current directory,
- collects variable names used in
process.env/import.meta.env, - creates missing env files for the supported set above,
- appends missing keys as blank entries while preserving existing values.
By default these extensions are scanned:
.js,.jsx,.ts,.tsx,.mjs,.cjs.json,.yaml,.yml.ipynb
You can change this by calling findReferencedEnvVars from the module API.
Given a project with:
src/lib/db.ts
src/app/page.tsxWhere those files contain:
// src/lib/db.ts
export const dbUrl = process.env.DATABASE_URL;
export const featureFlag = process.env['NEXT_PUBLIC_FLAG'];
// src/app/page.tsx
const token = import.meta.env.AUTH_TOKEN;Running from the project root:
npx vercel-env-createCreates/updates (if missing) all supported env files and adds:
# resulting files (excerpt)
.env
# ... existing content
AUTH_TOKEN=
DATABASE_URL=
NEXT_PUBLIC_FLAG=If you already have existing keys, they are preserved and only missing keys are appended.
# existing .env before
DATABASE_URL=postgres://...After running:
.env
DATABASE_URL=postgres://...
AUTH_TOKEN=
NEXT_PUBLIC_FLAG=Use --push after local sync to push discovered variable values to Vercel:
vercel-env-create --pushBehavior:
- If your project is linked to Vercel, the linked project is used automatically.
- If not linked, you get an interactive clack multi-select UI to choose one or more Vercel projects.
- You can choose target environment with an interactive clack select (
development,preview,production).
Options:
--project <name>- Target one or more projects explicitly (repeatable).
--environment <name>- Set target environment without interactive selection.
--env-file <file>- Source env file used for values (default:
.env).
- Source env file used for values (default:
--yes- Run non-interactively (required in non-TTY contexts).
The tool uses your existing local Vercel CLI authentication (vercel login).
If a referenced variable has no value in the source file, that variable is skipped during push.
If either .env.example or .env.local.example exists:
- the tool will seed new env files from the first example file it finds,
- no new keys are appended automatically (the file contents are preserved as-is).
.env.exampleis intentionally supported for bootstrap defaults..env*.localfiles are not meant to be committed because they contain secrets.- If you need a stricter scan surface, import
findReferencedEnvVarsfrom the package and build your own wrapper.
Contributions are welcome. Open an issue or submit a pull request.
Licensed under the MIT License.
Shoutout to HiDeoo for vercel-env-push and create-app, which inspired this CLI.