Overview
ARCA uses environment variables to configure both the backend (NestJS) and frontend (Next.js) applications. This guide details all configuration options.Backend Configuration
The backend application (apps/backend) uses the following environment variables.
Database Configuration
PostgreSQL connection string for PrismaFormat:Example:Production Example:
JWT Authentication
Secret key for signing JWT tokens
JWT token audience claim (optional)
JWT token issuer claim (optional)
JWT token time-to-live (optional)
Server Configuration
Port for the backend server
Allowed CORS origin(s) for the frontendDevelopment:Production:Multiple origins:
Node.js environmentThis affects which
.env file is loaded (.env.development, .env.production, etc.)Complete Backend .env Example
Frontend Configuration
The frontend application (apps/frontend) uses Next.js public environment variables.
Next.js environment variables prefixed with
NEXT_PUBLIC_ are exposed to the browser. Never include secrets in these variables.API Configuration
Backend API base URLDevelopment:Production:
NextAuth Configuration
ARCA uses NextAuth for authentication. Configure these inapps/frontend/.env.local:
The canonical URL of your siteDevelopment:Production:
Secret key for encrypting NextAuth tokens
Complete Frontend .env Example
Environment File Priority
Both applications follow standard environment file loading:Backend (NestJS)
Files are loaded in this order (later files override earlier ones):
.env.env.${NODE_ENV}(e.g.,.env.production)- Environment variables set in the shell
Security Best Practices
Use Strong Secrets
Use Strong Secrets
Generate cryptographically secure secrets:
Separate Development and Production
Separate Development and Production
Use different values for development and production:
- Different database credentials
- Different JWT secrets
- Different API URLs
Use Environment Variables in Production
Use Environment Variables in Production
Don’t use
.env files in production. Instead:- Set environment variables directly in your hosting platform
- Use secrets management (AWS Secrets Manager, etc.)
- Use container orchestration secrets (Docker Swarm, Kubernetes)
Validate Environment Variables
Validate Environment Variables
The backend uses
@nestjs/config for validation. Add validation schemas for required variables.Deployment-Specific Configuration
- Vercel (Frontend)
- Railway/Heroku (Backend)
- Docker
Add environment variables in Vercel dashboard:
- Go to Project Settings → Environment Variables
- Add:
NEXT_PUBLIC_API_URLNEXTAUTH_URLNEXTAUTH_SECRET
- Set appropriate values for Production/Preview/Development
Troubleshooting
Environment Variables Not Loading
Environment Variables Not Loading
- Ensure file names are correct (
.env, notenvor.env.txt) - Check file is in the correct directory (
apps/backendorapps/frontend) - Restart the development server after changing
.envfiles - For Next.js, use
NEXT_PUBLIC_prefix for client-side variables
CORS Errors
CORS Errors
- Verify
CORS_ORIGINmatches your frontend URL exactly - Include protocol (
http://orhttps://) - Don’t include trailing slash
- Check browser console for the exact origin being rejected
JWT Token Errors
JWT Token Errors
- Ensure
JWT_SECRETis set and matches on all instances - Verify
JWT_TTLformat is valid - Check token expiration settings
Next Steps
Database Setup
Configure and manage your PostgreSQL database
Production Deployment
Deploy to production environments