Environment Configuration
WhatDoc requires environment variables to be configured for both the server and client. This guide explains each variable and how to set them up.Server Configuration
The server requires several environment variables to connect to MongoDB, authenticate users, and interact with external APIs.Server Environment Variables Explained
Database Configuration
MONGO_URI
- Description: MongoDB connection string
- Required: Yes
- Local example:
mongodb://localhost:27017/whatdoc - Atlas example:
mongodb+srv://username:[email protected]/whatdoc - Notes: Ensure MongoDB is running before starting the server
Authentication
JWT_SECRET
- Description: Secret key for signing JWT tokens
- Required: Yes
- Example:
your-secret-key-change-this-in-production - Notes: Use a strong, random string in production. Generate with:
GITHUB_CLIENT_ID
- Description: GitHub OAuth App Client ID
- Required: Yes (for GitHub authentication)
- Example:
Iv1.a1b2c3d4e5f6g7h8 - Notes: Obtain from your GitHub OAuth App settings
GITHUB_CLIENT_SECRET
- Description: GitHub OAuth App Client Secret
- Required: Yes (for GitHub authentication)
- Example:
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0 - Notes: Keep this secret! Never commit to version control
AI Configuration
GEMINI_API_KEY
- Description: Google Gemini API key for AI-powered documentation generation
- Required: Yes
- Example:
AIzaSyABC123def456GHI789jkl012MNO345pqr - Notes: Get your free key from Google AI Studio
Server Settings
PORT
- Description: Port number for the Express server
- Required: No (defaults to 3000)
- Example:
3000 - Notes: Change if port 3000 is already in use
CLIENT_URL
- Description: URL where the client application is running
- Required: Yes
- Development:
http://localhost:5173 - Production: Your frontend domain (e.g.,
https://docs.yourcompany.com) - Notes: Used for CORS and redirect URLs
CORS_ORIGINS
- Description: Comma-separated list of allowed CORS origins
- Required: Yes
- Development:
http://localhost:5173,http://localhost:4173 - Production: Your frontend domains
- Notes: Port 4173 is Vite’s preview server
APP_DOMAIN
- Description: Base domain for the application
- Required: Yes
- Development:
localhost - Production: Your domain (e.g.,
yourcompany.com) - Notes: Used for subdomain generation (e.g.,
project.yourcompany.com)
Client Configuration
The client requires minimal configuration to connect to the API server.Client Environment Variables Explained
VITE_API_URL
- Description: URL of the backend API server
- Required: Yes
- Development:
http://localhost:3000 - Production: Your API domain (e.g.,
https://api.yourcompany.com) - Notes: Must match the server’s
PORTconfiguration
VITE_APP_DOMAIN
- Description: Domain where the client is running
- Required: Yes
- Development:
localhost:5173 - Production: Your frontend domain without protocol (e.g.,
docs.yourcompany.com) - Notes: Used for subdomain-based doc routing
Start the Services
Once configuration is complete, you can start both services.Start the server
In a terminal, from the You should see:
server directory:For development with auto-reload, use
npm run dev instead.Verify services are running
- Open your browser to http://localhost:5173
- You should see the WhatDoc landing page
- Try signing in with GitHub to verify OAuth is working
Production Deployment
For production deployments, additional configuration is recommended:Build the client for production
Build the client for production
dist directory. Serve these files with nginx, Apache, or a CDN.Use a process manager for the server
Use a process manager for the server
Install PM2 to keep your server running:
Configure reverse proxy
Configure reverse proxy
Use nginx or Apache to:
- Serve the client build files
- Proxy API requests to the Express server
- Handle SSL/TLS certificates
- Enable gzip compression
Set up environment-specific configs
Set up environment-specific configs
For production:
- Use strong, unique
JWT_SECRET - Point
MONGO_URIto a production database - Update
CLIENT_URL,CORS_ORIGINS, andAPP_DOMAINto your domains - Update GitHub OAuth callback URLs
- Consider using environment variable management tools like Docker secrets or AWS Parameter Store
Troubleshooting
MongoDB connection failed- Verify MongoDB is running:
mongosh(local) or test connection string (Atlas) - Check
MONGO_URIformat is correct - Ensure network access is allowed (for Atlas, check IP whitelist)
- Verify
GITHUB_CLIENT_IDandGITHUB_CLIENT_SECRETare correct - Check OAuth callback URL matches:
http://localhost:3000/api/auth/github/callback - Ensure
CLIENT_URLis set correctly for redirects
- Verify
CORS_ORIGINSincludes your client URL - Check
CLIENT_URLmatches where your frontend is running - Ensure both services are running
- Change
PORTin server.envto an available port - Update
VITE_API_URLin client.envto match
Next Steps
Your WhatDoc instance is now running! You can:- Sign in with GitHub
- Import a repository
- Choose a documentation template
- Generate beautiful docs in seconds
server and client directories.