Env Var
You might say
I know a secret key shouldn't go in the code. Where should I put it?
Provide configuration outside the source codeEnvironment variables supply values such as API endpoints, feature settings, and secret keys when a program starts. Public browser variables are visible to visitors, even if their names come from an environment file. Keep real secrets on the server and document the required variable names with safe examples.
Know first
When to use it
- Set different values for development and production
- Provide server-side credentials
- Configure an API endpoint
- Turn deployment-specific features on or off
When NOT to use it
- Commit a file containing real secrets
- Put private keys in variables exposed to browser code
- Assume changing a value updates a running process automatically
- Leave required variables undocumented
Anatomy
OPENAI_API_KEY=sk-proj-•••••• # For local development, please do not submit
It is the convention to use all uppercase letters and underlines, so read this name in the code.
After the equal sign is the actual configuration value; when the key is included, it must be covered before taking the screenshot.
Notes starting with # will be ignored by the program.
Variants
.env
.env
For local development use, should usually be excluded by .gitignore
Platform Env
Vercel → Settings → Env
Add another copy to the deployment platform settings page.
.env.example
.env.example
Telling others what to wear is not true.
Typical use cases
Database connection
API credential
Site URL
Feature setting