OS Trading Engine
Technical Documentation
Configuration
Environment Variables

Environment Variables

This page documents all environment variables used by Nexgent. Variables are organized by package and purpose.

⚠️

Never commit secrets to version control. Use .env files (gitignored) or a secrets manager.


Backend Variables

Required

These variables must be set for the backend to function.

VariableDescriptionExample
DATABASE_URLPostgreSQL connection stringpostgresql://user:pass@host:5432/nexgent?schema=public
JWT_SECRETSecret for signing JWT tokens (min 32 chars)your-secure-secret-minimum-32-chars
🚫

The backend will fail to start if DATABASE_URL or JWT_SECRET (under 32 chars) are missing.

Jupiter

VariableDescription
JUPITER_API_KEYJupiter API key for swap execution

Get your Jupiter API key at dev.jup.ag (opens in a new tab). While not strictly required for startup, swap execution will fail without it.

Wallets

VariableDescription
WALLET_1Base58-encoded private key (or JSON array format)
⚠️

Wallet private keys are only needed for live trading. Simulation mode works without them.

Optional Overrides

These have sensible defaults for local development.

VariableDefaultDescription
PORT4000HTTP server port
NODE_ENVdevelopmentEnvironment mode (development, production, test)
CORS_ORIGINhttp://localhost:3000Allowed CORS origins (comma-separated)
REDIS_HOSTlocalhostRedis server hostname
REDIS_PORT6379Redis server port
DATABASE_TEST_URL-PostgreSQL connection for test database

Railway uses REDISHOST, REDISPORT, REDISPASSWORD (no underscore). Both formats are supported for compatibility.


Frontend Variables

Required

VariableDescriptionExample
NEXTAUTH_SECRETSecret for NextAuth session encryption (min 32 chars)your-secure-nextauth-secret

In development, NextAuth will warn if the secret is missing but still work. In production, it will throw an error.

Optional

VariableDefaultDescription
NEXT_PUBLIC_API_URLhttp://localhost:4000Backend API URL
💡

Variables prefixed with NEXT_PUBLIC_ are exposed to the browser. Never use this prefix for secrets.


Example Configuration

Development

Backend (packages/backend/.env):

# PostgreSQL connection URL (required)
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/nexgent?schema=public"

# JWT secret for authentication (required in production)
# Generate with: pnpm generate-secret
JWT_SECRET="your-secret-here-minimum-32-characters"

# Jupiter API key
# Get your key from: https://dev.jup.ag/
JUPITER_API_KEY=your-jupiter-api-key

# Wallet private keys for live trading (optional, simulation works without them)
# Format: Base58 string or JSON array [1,2,3,...] (64 bytes)
WALLET_1=your-wallet-private-key

# --- Optional overrides (defaults work for local development) ---
PORT=4000
NODE_ENV=development
CORS_ORIGIN=http://localhost:3000
REDIS_HOST=localhost
REDIS_PORT=6379
DATABASE_TEST_URL="postgresql://postgres:postgres@localhost:5432/nexgent_test?schema=public"

Frontend (packages/frontend/.env.local):

# NextAuth.js secret for JWT encryption (required in production)
# Generate with: pnpm generate-secret
NEXTAUTH_SECRET=your-secret-here-minimum-32-characters

# Backend API URL (optional, defaults to http://localhost:4000)
NEXT_PUBLIC_API_URL=http://localhost:4000

Production

Backend:

# Required
DATABASE_URL=postgresql://user:password@host:5432/nexgent?sslmode=require
JWT_SECRET=<secure-random-string-32-chars-minimum>
JUPITER_API_KEY=<your-jupiter-api-key>

# Server
NODE_ENV=production
PORT=4000
CORS_ORIGIN=https://yourdomain.com

# Redis
REDIS_HOST=redis.internal
REDIS_PORT=6379

# Wallet (for live trading)
WALLET_1=<base58-private-key>

Frontend:

NEXTAUTH_SECRET=<secure-random-string-32-chars-minimum>
NEXT_PUBLIC_API_URL=https://api.yourdomain.com

Generating Secrets

Use the included scripts to generate secure secrets:

# Generate NEXTAUTH_SECRET (frontend)
pnpm generate-secret
 
# Generate JWT_SECRET (backend)
pnpm generate-secret:backend

Each script outputs a ready-to-use environment variable line you can copy directly into your .env file.


Startup Validation

The backend validates required variables at startup:

if (!process.env.JWT_SECRET) {
  throw new Error('JWT_SECRET environment variable is required');
}
 
if (!process.env.DATABASE_URL) {
  throw new Error('DATABASE_URL environment variable is required');
}

Troubleshooting

Missing JWT_SECRET

Error: JWT_SECRET environment variable is required

Solution: Generate a secure secret (minimum 32 characters) and add to your .env file.

Missing DATABASE_URL

Error: DATABASE_URL environment variable is required

Solution: Add your PostgreSQL connection string to .env.

Redis Connection Failed

Error: Redis connection failed

Solution: Ensure Redis is running and REDIS_HOST/REDIS_PORT are correct.

CORS Errors in Production

Access-Control-Allow-Origin header missing

Solution: Set CORS_ORIGIN to your frontend domain(s), comma-separated if multiple.