Next.js app environment variables
Create a.env file in the next-app/ directory with the following variables:
Database
For local development, you can use a local PostgreSQL instance. For production, use a managed database service like Supabase or Neon.
Authentication
NEXTAUTH_SECRET
NEXTAUTH_SECRET
Secret key used by NextAuth.js for encrypting tokens and session data. Generate a secure random string:
NEXTAUTH_URL
NEXTAUTH_URL
The canonical URL of your site. For local development, use
http://localhost:3000. For production, use your deployed URL.OAuth providers
Create OAuth credentials
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google+ API
- Go to Credentials → Create Credentials → OAuth client ID
Email service
- Gmail (requires app-specific password)
- SendGrid
- AWS SES
- Mailgun
Cloudinary (image uploads)
WebSocket connection
NEXT_PUBLIC_ prefix makes this variable available in the browser.
JWT secret (shared)
WebSocket server environment variables
Create a.env file in the ws/ directory:
PORT
Port number for the WebSocket server. Default is8080.
NEXT_PUBLIC_SECRET
JWT secret for verifying tokens from the Next.js app. Must match theNEXT_PUBLIC_SECRET in the Next.js .env file.
Example configuration files
Environment-specific configurations
Development
Development
For local development:
- Use
http://localhost:3000for the Next.js app - Use
ws://localhost:8080for WebSocket connections - Use a local PostgreSQL database
- Use local Redis instance
Production
Production
For production deployment:
- Use HTTPS URLs for the Next.js app
- Use WSS (secure WebSocket) URLs
- Use managed database services (Supabase, Neon, etc.)
- Use managed Redis services (Upstash, Redis Cloud, etc.)
- Generate strong, unique secrets for all keys
Security best practices
- Generate strong random secrets for
NEXTAUTH_SECRETandNEXT_PUBLIC_SECRET - Use different secrets for development and production
- Rotate secrets regularly in production
- Use environment variable management tools (Vercel, AWS Systems Manager, etc.) in production
- Limit OAuth redirect URIs to your actual domains
- Use read-only database credentials where possible
Verifying configuration
After setting up your environment variables:Next steps
- Set up the database schema and migrations
- Complete the local development setup
- Explore the Architecture to understand the system design