Environment Variables
This page lists all environment variables that Medusa recognizes and uses for configuration.Environment variables are loaded from
.env files in development. In production, set them in your hosting environment.Required Variables
These variables are required for Medusa to run:DATABASE_URL
PostgreSQL connection string.postgres://[user][:password]@[host][:port]/[dbname]
Default: postgres://localhost/medusa-starter-default
JWT_SECRET
Secret key for signing JWT tokens.supersecret (development only)
Generate a secure secret:
COOKIE_SECRET
Secret key for signing session cookies.supersecret (development only)
HTTP Configuration
PORT
Port number for the HTTP server.9000
NODE_ENV
Application environment.development, production, prod
Default: development
STORE_CORS
Allowed CORS origins for store routes.http://localhost:8000
Format: Comma-separated list of URLs
ADMIN_CORS
Allowed CORS origins for admin routes.http://localhost:7000,http://localhost:7001,http://localhost:5173
Format: Comma-separated list of URLs
AUTH_CORS
Allowed CORS origins for auth routes.ADMIN_CORS
Format: Comma-separated list of URLs
JWT Configuration
JWT_PUBLIC_KEY
Public key for asymmetric JWT verification.When using asymmetric JWT, configure
jwtOptions.algorithm and jwtVerifyOptions.algorithms in medusa-config.ts.Redis Configuration
REDIS_URL
Redis connection URL.redis://[user][:password]@[host][:port]
Default: Not set (uses in-memory implementations)
CACHE_REDIS_URL
Separate Redis instance for caching.REDIS_URL
Worker Mode
MEDUSA_WORKER_MODE
Determines how the instance handles HTTP requests and background jobs.shared: Handle both HTTP and jobs (default)server: Only handle HTTP requestsworker: Only handle background jobs
shared
Production setup:
Admin Configuration
MEDUSA_BACKEND_URL
Backend URL for the admin dashboard./ (browser origin)
DISABLE_ADMIN
Disable the admin dashboard.false
STOREFRONT_URL
Storefront URL for generating customer-facing links from admin.Logging
LOG_LEVEL
Logging level for the application.error, warn, info, debug
Default: info
Production recommendation: error or warn
Medusa Cloud
These variables are used when deploying to Medusa Cloud:EXECUTION_CONTEXT
MEDUSA_CLOUD_ENVIRONMENT_HANDLE
MEDUSA_CLOUD_SANDBOX_HANDLE
MEDUSA_CLOUD_API_KEY
MEDUSA_CLOUD_WEBHOOK_SECRET
MEDUSA_CLOUD_EMAILS_ENDPOINT
MEDUSA_CLOUD_PAYMENTS_ENDPOINT
MEDUSA_CLOUD_OAUTH_AUTHORIZE_ENDPOINT
MEDUSA_CLOUD_OAUTH_TOKEN_ENDPOINT
MEDUSA_CLOUD_OAUTH_CALLBACK_URL
MEDUSA_CLOUD_OAUTH_DISABLED
Session Configuration
SESSION_STORE
Session storage backend.dynamodb (when using DynamoDB for sessions)
Default: In-memory or Redis (based on REDIS_URL)
DynamoDB Session Variables
When using DynamoDB for session storage:File Storage (S3)
When using S3 for file storage:S3_BUCKET
S3_REGION
S3_ACCESS_KEY_ID
S3_SECRET_ACCESS_KEY
S3_ENDPOINT
S3_FILE_URL
S3_PREFIX
Payment Providers
Stripe
PayPal
Notification Providers
SendGrid
Mailchimp
Feature Flags
MEDUSA_FF_TRANSLATION
Enable translation module.false
MEDUSA_FF_RBAC
Enable role-based access control.false
ENABLE_INDEX_MODULE
Enable the index/search module.false
Database Internal Variables
These are used internally for database connection handling:__MEDUSA_DB_CONNECTION_MAX_RETRIES
Maximum retries for database connection.5
__MEDUSA_DB_CONNECTION_RETRY_DELAY
Delay between connection retries in milliseconds.1000
DB_MIGRATION_CONCURRENCY
Number of concurrent migrations to run.Module-Specific Database URLs
You can configure separate databases for specific modules:MEDUSA_DATABASE_URL
Shared database for all modules.Module Database URLs
{MODULE_NAME}_DATABASE_URL
Example .env File
Here’s a complete example for production:.env
Security Best Practices
- Use strong secrets: Generate random values for JWT_SECRET and COOKIE_SECRET
- Different secrets per environment: Don’t reuse secrets between development, staging, and production
- Rotate secrets regularly: Update secrets periodically and after security incidents
- Use secret management: Consider using AWS Secrets Manager, HashiCorp Vault, or similar
- Limit access: Only grant access to environment variables to those who need it
- Audit changes: Track who changes environment variables and when
Loading Environment Variables
Development
Medusa automatically loads variables from.env files:
Production
Set environment variables in your hosting platform:- Docker: Use
-eflag ordocker-compose.yml - Kubernetes: ConfigMaps and Secrets
- Heroku: Config Vars in dashboard or CLI
- AWS: Systems Manager Parameter Store or Secrets Manager
- Vercel/Netlify: Environment variables in dashboard
Multiple Environment Files
You can use different.env files: