Backend Environment Variables
Configure these variables inapps/server/.env
Required Variables
MongoDB Configuration
MONGO_URI
MONGO_URI
Type: String (Required)MongoDB connection string for the KeyBox database.Development:Production (MongoDB Atlas):Docker:Connection Options:
The database name
keyboxDB can be customized to any name you prefer.- Server selection timeout is set to 5000ms in the code
- The application will exit if MongoDB connection fails
- Mongoose will create collections automatically
Authentication & Security
JWT_SECRET
JWT_SECRET
Type: String (Required)Secret key for signing and verifying JWT tokens used for user authentication.Generate a secure secret:Used in:
src/controllers/auth.controller.ts- Login token generationsrc/middleware/jwt.ts- Token verificationsrc/routes/googleAuth.routes.ts- OAuth callback tokens
SESSION_SECRET
SESSION_SECRET
Type: String (Optional)Secret for Express session middleware (used for OAuth flows).Default: Used in:
"your-session-secret"While optional, you should set this to a unique value in production.
src/app.ts- Express session configuration
LICENSE_SECRET_KEY
LICENSE_SECRET_KEY
Type: String (Required)Secret key used for encrypting and validating license keys.Security recommendations:
- Minimum 32 characters
- Store securely (use secret management service)
- Backup this value before rotating
- Use same value across all environments handling same licenses
Google OAuth Configuration
GOOGLE_CLIENT_ID
GOOGLE_CLIENT_ID
Type: String (Required for OAuth)Google OAuth 2.0 Client ID from Google Cloud Console.How to obtain:
- Go to Google Cloud Console
- Create or select a project
- Enable Google+ API
- Go to Credentials → Create Credentials → OAuth 2.0 Client ID
- Set application type to “Web application”
- Copy the Client ID
src/config/googleStrategy.ts- Passport Google OAuth strategy
GOOGLE_CLIENT_SECRET
GOOGLE_CLIENT_SECRET
Type: String (Required for OAuth)Google OAuth 2.0 Client Secret from Google Cloud Console.Used in:
src/config/googleStrategy.ts- Passport Google OAuth strategy
GOOGLE_CALLBACK_URL
GOOGLE_CALLBACK_URL
Type: String (Required for OAuth)Callback URL for Google OAuth redirects.Used in:
This URL must be registered in Google Cloud Console under “Authorized redirect URIs”.
src/config/googleStrategy.ts- OAuth callback configuration
Server Configuration
PORT
PORT
Type: Number (Optional)Port number the server listens on.Default:
8000Common values:- Development:
5000or8000 - Production:
80(HTTP) or443(HTTPS) - Cloud platforms often set this automatically
src/server.ts- Server startup
FRONTEND_URL
FRONTEND_URL
Type: String (Required)URL of the frontend application for CORS and OAuth redirects.Used in:
src/routes/googleAuth.routes.ts- OAuth success redirects- CORS configuration (currently set to
*, should be restricted in production)
Redis Configuration
REDIS_PASSWORD
REDIS_PASSWORD
Type: String (Optional)Password for Redis authentication.Note: The Redis host and port are currently hardcoded in Used in:
src/lib/redis.ts:- Host:
redis-10357.c212.ap-south-1-1.ec2.cloud.redislabs.com - Port:
10357
src/lib/redis.ts- Redis client configuration
Optional Configuration
NODE_ENV
NODE_ENV
Type: String (Optional)Environment mode for the application.Values:
development- Development modetest- Testing mode (disables certain middleware)production- Production mode
- Controls database middleware in
src/app.ts - Affects MongoDB transactions in
src/controllers/project.controller.ts - Changes logging behavior
src/app.ts- Conditional middleware loadingsrc/tests/setup.ts- Test environment configuration
Frontend Environment Variables
Configure these variables inapps/web/.env.local
Required Variables
NEXT_PUBLIC_API_URL
NEXT_PUBLIC_API_URL
Type: String (Required)Base URL of the backend API server.Used in:
lib/api.ts- Axios base URL configurationapp/api/axiosInstance.ts- Alternative Axios instance- OAuth redirect URLs in login/signup pages
Environment Files
Backend Files
Frontend Files
Environment Variable Priority
Next.js loads environment variables in this order (highest priority first):.env.$(NODE_ENV).local.env.local(not loaded whenNODE_ENV=test).env.$(NODE_ENV).env
Security Best Practices
Deployment Platform Configuration
Vercel
- Go to Project Settings → Environment Variables
- Add each variable with its value
- Select environments (Production, Preview, Development)
- Redeploy to apply changes
Railway/Render
- Go to your service/app settings
- Navigate to Environment Variables section
- Add variables as key-value pairs
- Save and redeploy
Docker
Pass environment variables via: Docker run:Kubernetes
ConfigMap for non-sensitive data:Validation
Add runtime validation for critical environment variables:Troubleshooting
Variables Not Loading
Backend:- Ensure
dotenvis imported before other modules - Check file is named exactly
.env - Verify file is in correct directory (
apps/server/) - Restart the server after changes
- Ensure variable has
NEXT_PUBLIC_prefix (for client-side) - Rebuild the application (
pnpm build) - Clear Next.js cache:
rm -rf .next - Restart dev server
OAuth Not Working
- Verify all Google OAuth variables are set
- Check callback URL matches Google Console
- Ensure URLs don’t have typos or extra spaces
- Verify Google Cloud project has OAuth consent configured
MongoDB Connection Fails
- Test connection string with
mongosh - Check IP whitelist (MongoDB Atlas)
- Verify credentials are correct
- Ensure database name is included in URI
Next Steps
- Backend Setup - Deploy the Node.js server
- Frontend Setup - Deploy the Next.js dashboard
- Google OAuth Setup - Configure OAuth authentication