Skip to main content
DeployHub provides comprehensive environment variable management for both build-time and runtime configuration of your applications.

Environment Variable Storage

Environment variables are stored as a Map in the Project model:
Using MongoDB Map type allows flexible key-value storage without predefined schemas.

Setting Environment Variables

Environment variables can be set during deployment creation:
API Request:

Static Sites (Build-Time Variables)

For static sites, environment variables are injected during the Docker build process:

Variable Injection

Dockerfile Integration

Variables prefixed with VITE_, REACT_APP_, or NEXT_PUBLIC_ are accessible in your frontend code.
Example Usage in React:

Node.js Applications (Runtime Variables)

For Node.js apps, environment variables are passed to the container at runtime:

Container Environment

Example Variables:
Access in Node.js:
Node.js environment variables are available through process.env and can be updated without rebuilding.

Updating Environment Variables

Update environment variables through the project settings API:
API Endpoint:
For static sites, changing environment variables requires a full rebuild. For Node.js apps, redeploy to apply changes.

Retrieving Environment Variables

Get current environment variables:
API Endpoint:
Response:

Redeployment with Updated Variables

When environment variables change during redeployment:
The redeployment worker:
  1. Fetches latest environment variables from database
  2. Rebuilds image (static) or recreates container (Node.js)
  3. Injects updated variables into build/runtime

Security Best Practices

Secrets Management

DO:
  • Use environment variables for API keys, tokens, passwords
  • Never commit secrets to Git
  • Rotate secrets regularly
DON’T:
  • Hardcode secrets in source code
  • Share secrets in plain text
  • Use the same secrets for dev/prod
Use SCREAMING_SNAKE_CASE for environment variable names to match industry conventions.

Framework-Specific Variables

Vite (React, Vue, Svelte)

Variables must be prefixed with VITE_:

Create React App

Variables must be prefixed with REACT_APP_:

Next.js

Public variables must be prefixed with NEXT_PUBLIC_:

Node.js / Express

No prefix required:

Common Environment Variables

Backend Services

Frontend Applications

Validation Rules

  • Keys cannot be empty or whitespace-only
  • Values are stored as strings (convert to numbers/booleans in code)
  • Maximum size: Depends on MongoDB document limit (16MB)
  • Keys are case-sensitive

Debugging Environment Variables

Check Build Logs

For static sites, verify variables are injected:

Inspect Container Environment

For Node.js apps:

Common Issues

Variable not accessible in frontend:
  • API_URL - No prefix
  • VITE_API_URL - Correct prefix
Variable showing as undefined:
  • Check spelling and case
  • Verify it’s set in project settings
  • For static: Rebuild required
  • For Node.js: Redeploy required

API Reference

Get Environment Variables

Returns all project settings including environment variables.

Update Environment Variables

This endpoint replaces all environment variables. Include all keys you want to keep.

Limitations

  • No built-in encryption (store sensitive data carefully)
  • Variables visible to project owner in API responses
  • No versioning or history tracking
  • Static sites require rebuild for changes to take effect

Best Practices Summary

1

Use Descriptive Names

Name variables clearly: DATABASE_URL not DB
2

Prefix Frontend Variables

Use VITE_, REACT_APP_, or NEXT_PUBLIC_ prefixes
3

Separate Environments

Use different values for development, staging, production
4

Never Commit Secrets

Keep .env files out of version control
5

Redeploy After Changes

Remember to redeploy for changes to take effect