Overview
MeetMates uses environment variables to configure both the frontend and backend applications. This page documents all available environment variables, their purposes, and how to obtain the necessary credentials.Backend Environment Variables
Create a.env file in the backend/ directory with the following variables:
MONGODB_URI
Required: YesType: String
Example:
mongodb://localhost:27017/meetmates
MongoDB connection string for the database.
How to configure:
For Local MongoDB:
For MongoDB Atlas:
- Create an account at MongoDB Atlas
- Create a new cluster (free tier available)
- Click “Connect” → “Connect your application”
- Copy the connection string and replace
<password>and<dbname>:
- For Atlas, whitelist your IP address in Network Access
- Use a strong password without special characters that need URL encoding
- The database name (
meetmates) can be customized
backend/server.js:40- Mongoose connection
JWT_SECRET
Required: YesType: String
Example:
your-super-secret-jwt-key-change-this-in-production
Secret key used to sign and verify JWT authentication tokens.
How to configure:
Generate a strong random secret:
- Use a different secret for development and production
- Keep this value secret and never commit it to version control
- Minimum recommended length: 32 characters
- Changing this value will invalidate all existing JWT tokens
backend/routes/auth.js:77-83- Token signing during login/signupbackend/routes/auth.js:156- Token signing for Google OAuthbackend/middleware/auth.js:21- Token verificationbackend/server.js:90- Socket.IO authentication
CORS_ORIGIN
Required: YesType: String (comma-separated URLs)
Default:
http://localhost:5173,https://www.meetmates.spaceExample:
http://localhost:5173,http://localhost:3000,https://yourdomain.com
Allowed origins for Cross-Origin Resource Sharing (CORS).
How to configure:
- Include the protocol (
http://orhttps://) - Do not include trailing slashes
- For local development, ensure the port matches your frontend dev server
- Vite’s default port is
5173
backend/server.js:20-34- CORS middleware configurationbackend/server.js:111-116- Socket.IO CORS configuration
PORT
Required: NoType: Number
Default:
3001Example:
3001
Port number on which the backend server will run.
How to configure:
- If not specified, defaults to
3001 - Ensure the port is not already in use
- Update frontend
VITE_BACKEND_URLif you change this - Common ports:
3000,3001,5000,8080
backend/server.js:388-391- Server initialization
GOOGLE_CLIENT_ID
Required: Yes (for Google OAuth)Type: String
Example:
123456789-abcdefghijklmnop.apps.googleusercontent.com
Google OAuth 2.0 Client ID for authentication.
How to configure:
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google+ API:
- Navigate to “APIs & Services” → “Library”
- Search for “Google+ API” and enable it
- Create OAuth 2.0 credentials:
- Go to “Credentials” → “Create Credentials” → “OAuth 2.0 Client ID”
- Application type: “Web application”
- Name: “MeetMates” (or your choice)
- Configure authorized origins:
- Authorized JavaScript origins:
http://localhost:5173(development)https://yourdomain.com(production)
- Authorized redirect URIs:
http://localhost:5173(development)https://yourdomain.com(production)
- Authorized JavaScript origins:
- Copy the Client ID
- This value is used on both frontend and backend
- Keep the Client Secret secure (not needed for frontend OAuth)
- Configure the OAuth consent screen with your app details
- For college-specific authentication, restrict domain in OAuth settings
backend/routes/auth.js:10- OAuth2Client initializationbackend/routes/auth.js:107- Token verification
NODE_ENV
Required: NoType: String
Values:
development, production, testDefault:
undefinedExample:
development
Specifies the environment in which the application is running.
How to configure:
- Affects error message verbosity
- Some packages behave differently based on this value
- Production mode typically disables verbose logging
backend/routes/auth.js:191- Conditional error details
Frontend Environment Variables
Create a.env file in the frontend/ directory with the following variables:
Vite requires environment variables to be prefixed with
VITE_ to be exposed to the client-side code.VITE_BACKEND_URL
Required: YesType: String
Example:
http://localhost:3001
The base URL of the backend API server.
How to configure:
- Must match the backend server URL and port
- Include the protocol (
http://orhttps://) - Do not include trailing slashes
- Do not include
/api- it’s added in the code - Used for both REST API calls and Socket.IO connections
frontend/src/Socket.jsx:3- Socket.IO connectionfrontend/src/components/Login.jsx:39- Google login APIfrontend/src/components/Login.jsx:78-79- Login/signup endpointsfrontend/src/components/Login.jsx:156- Image-based loginfrontend/src/components/Login.jsx:199- Signup endpointfrontend/src/App.jsx:28- Token verification
VITE_GOOGLE_CLIENT_ID
Required: Yes (for Google OAuth)Type: String
Example:
123456789-abcdefghijklmnop.apps.googleusercontent.com
Google OAuth 2.0 Client ID for frontend authentication.
How to configure:
Use the same Client ID obtained from Google Cloud Console (see backend GOOGLE_CLIENT_ID above):
- Must exactly match the
GOOGLE_CLIENT_IDin backend.env - Used by Google Sign-In JavaScript library
- Exposed to client-side code (not a security risk)
- Required for Google One Tap and Sign-In Button
frontend/src/components/Login.jsx:8- Client ID constantfrontend/src/googleAuth.js:2-6- Google Sign-In initialization
Environment Variable Templates
Backend .env Template
Create backend/.env:
Frontend .env Template
Create frontend/.env:
Production Considerations
Security Best Practices
-
Never commit
.envfiles to version control- Add
.envto.gitignore - Both frontend and backend
.gitignorealready exclude.env
- Add
-
Use different credentials for production
- Different
JWT_SECRET - Different MongoDB database
- Production Google OAuth credentials
- Different
-
Use environment variable management
- For deployment: Vercel, Netlify, Railway, etc. have built-in env var management
- For VPS: Use services like Vault, AWS Secrets Manager, or .env files with proper permissions
-
Restrict CORS origins in production
Environment-Specific Configurations
Development
Staging
Production
Troubleshooting
Environment Variables Not Loading
Problem: Backend or frontend can’t read environment variables Solutions:- Ensure
.envfile is in the correct directory:- Backend:
backend/.env - Frontend:
frontend/.env
- Backend:
- Restart the development server after changing
.env - For Vite, ensure variables are prefixed with
VITE_ - Check for syntax errors (no spaces around
=)
CORS Errors Despite Configuration
Problem: Still getting CORS errors Solutions:- Verify
CORS_ORIGINincludes the exact frontend URL with protocol - Check for trailing slashes (shouldn’t have any)
- Ensure backend server restarted after
.envchange - Clear browser cache
- Check browser console for the exact origin being blocked
Google OAuth Not Working
Problem: Google Sign-In button doesn’t appear or OAuth fails Solutions:- Verify
VITE_GOOGLE_CLIENT_IDmatchesGOOGLE_CLIENT_ID - Check authorized JavaScript origins in Google Console
- Ensure you’re accessing the app from an authorized origin
- Look for errors in browser console
- Verify Google+ API is enabled in Google Cloud Console
MongoDB Connection Failed
Problem: “MongoDB connection error” Solutions:- Check
MONGODB_URIformat is correct - For Atlas: Verify IP whitelist and credentials
- For local: Ensure MongoDB service is running
- Test connection string with MongoDB Compass
- Check for special characters in password (URL encode them)
Next Steps
- Complete the Local Development Setup
- Understand the System Architecture
- Explore the API Reference