Skip to main content

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.
Format: postgres://[user][:password]@[host][:port]/[dbname] Default: postgres://localhost/medusa-starter-default

JWT_SECRET

Secret key for signing JWT tokens.
Default: supersecret (development only)
In production, this must be set to a strong, random value. Use at least 32 random characters.
Generate a secure secret:
Secret key for signing session cookies.
Default: supersecret (development only)
In production, this must be set to a strong, random value different from JWT_SECRET.

HTTP Configuration

PORT

Port number for the HTTP server.
Default: 9000

NODE_ENV

Application environment.
Values: development, production, prod Default: development

STORE_CORS

Allowed CORS origins for store routes.
Default: http://localhost:8000 Format: Comma-separated list of URLs

ADMIN_CORS

Allowed CORS origins for admin routes.
Default: http://localhost:7000,http://localhost:7001,http://localhost:5173 Format: Comma-separated list of URLs

AUTH_CORS

Allowed CORS origins for auth routes.
Default: Same as ADMIN_CORS Format: Comma-separated list of URLs

JWT Configuration

JWT_PUBLIC_KEY

Public key for asymmetric JWT verification.
Default: Not set (uses symmetric signing with JWT_SECRET)
When using asymmetric JWT, configure jwtOptions.algorithm and jwtVerifyOptions.algorithms in medusa-config.ts.

Redis Configuration

REDIS_URL

Redis connection URL.
Format: redis://[user][:password]@[host][:port] Default: Not set (uses in-memory implementations)
For production, Redis is strongly recommended for the event bus, cache, and workflow engine.

CACHE_REDIS_URL

Separate Redis instance for caching.
Default: Falls back to REDIS_URL

Worker Mode

MEDUSA_WORKER_MODE

Determines how the instance handles HTTP requests and background jobs.
Values:
  • shared: Handle both HTTP and jobs (default)
  • server: Only handle HTTP requests
  • worker: Only handle background jobs
Default: shared Production setup:

Admin Configuration

MEDUSA_BACKEND_URL

Backend URL for the admin dashboard.
Default: / (browser origin)

DISABLE_ADMIN

Disable the admin dashboard.
Default: false

STOREFRONT_URL

Storefront URL for generating customer-facing links from admin.
Default: Not set

Logging

LOG_LEVEL

Logging level for the application.
Values: error, warn, info, debug Default: info Production recommendation: error or warn

Medusa Cloud

These variables are used when deploying to Medusa Cloud:

EXECUTION_CONTEXT

Enables Medusa Cloud-specific configurations.

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.
Values: 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.
Default: false

MEDUSA_FF_RBAC

Enable role-based access control.
Default: false

ENABLE_INDEX_MODULE

Enable the index/search module.
Default: false

Database Internal Variables

These are used internally for database connection handling:

__MEDUSA_DB_CONNECTION_MAX_RETRIES

Maximum retries for database connection.
Default: 5

__MEDUSA_DB_CONNECTION_RETRY_DELAY

Delay between connection retries in milliseconds.
Default: 1000

DB_MIGRATION_CONCURRENCY

Number of concurrent migrations to run.
Default: Unlimited (or 1 if using pgstream)

Module-Specific Database URLs

You can configure separate databases for specific modules:

MEDUSA_DATABASE_URL

Shared database for all modules.

Module Database URLs

Format: {MODULE_NAME}_DATABASE_URL

Example .env File

Here’s a complete example for production:
.env

Security Best Practices

Never commit .env files to version control. Add .env to your .gitignore file.
  1. Use strong secrets: Generate random values for JWT_SECRET and COOKIE_SECRET
  2. Different secrets per environment: Don’t reuse secrets between development, staging, and production
  3. Rotate secrets regularly: Update secrets periodically and after security incidents
  4. Use secret management: Consider using AWS Secrets Manager, HashiCorp Vault, or similar
  5. Limit access: Only grant access to environment variables to those who need it
  6. 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 -e flag or docker-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:
Load specific file: