# API Base URL - Points to local backend
VITE_API_BASE=http://localhost:5000/api# API Base URL - Points to deployed backend
VITE_API_BASE=https://your-backend-app.onrender.com/apiNote: Replace your-backend-app.onrender.com with your actual backend URL
# MongoDB Connection String (Local)
MONGO_URI=mongodb://localhost:27017/proctesting
# Email (Contact Form)
# SMTP configuration for sending emails from the backend (Nodemailer)
# For Gmail, create an App Password (recommended) and use:
# SMTP_HOST=smtp.gmail.com
# SMTP_PORT=465
# SMTP_SECURE=true
# [email protected]
# SMTP_PASS=your_16_char_app_password
# Recipient for contact messages (defaults to [email protected])
# [email protected]
# Email (Contact Form)
# Brevo (Sendinblue) Transactional Emails configuration
# Create an API key in Brevo dashboard and set it here. Do NOT commit real keys.
# Recipient for contact messages (defaults to [email protected])
# [email protected]
BREVO_API_KEY=
BREVO_SENDER_EMAIL=
BREVO_SENDER_NAME=Contact Form
# CONTACT_RECEIVER=
# OR MongoDB Atlas (Cloud)
# MONGO_URI=mongodb+srv://username:[email protected]/proctesting?retryWrites=true&w=majority
# JWT Secret for token signing (use a strong random string)
JWT_SECRET=your-local-development-secret-key-at-least-32-chars
# Server Port
PORT=5000
# Frontend URL for CORS
# Either set a single URL:
CLIENT_URL=http://localhost:5173
# Or set multiple, comma-separated URLs (takes precedence over CLIENT_URL):
# CLIENT_URLS=http://localhost:5173,https://your-frontend.vercel.app
# Node Environment
NODE_ENV=development# MongoDB Connection String (MongoDB Atlas)
MONGO_URI=mongodb+srv://username:[email protected]/proctesting?retryWrites=true&w=majority
# JWT Secret (IMPORTANT: Use a different, strong secret for production)
JWT_SECRET=production-secret-key-must-be-very-long-and-random-at-least-64-characters-recommended
# Server Port (usually auto-assigned by hosting platform)
PORT=5000
# Frontend URL for CORS (your deployed frontend domain)
CLIENT_URL=https://your-frontend-app.vercel.app
# Or multiple allowed origins:
# CLIENT_URLS=https://your-frontend-app.vercel.app,https://preview-<id>--your-frontend.netlify.app
# Node Environment
NODE_ENV=productionnode -e "console.log(require('crypto').randomBytes(32).toString('hex'))"openssl rand -base64 32- Visit: https://www.random.org/strings/
- Generate a random alphanumeric string (min 32 characters)
- Project Settings → Environment Variables
- Add variable name:
VITE_API_BASE - Add variable value:
https://your-backend.onrender.com/api - Select environments: Production, Preview, Development
- Site settings → Build & deploy → Environment
- Click "Add variable"
- Key:
VITE_API_BASE - Value:
https://your-backend.onrender.com/api
- Dashboard → Your Web Service → Environment
- Add Environment Variables:
MONGO_URI=mongodb+srv://...JWT_SECRET=your-secret-keyCLIENT_URL=https://your-frontend.vercel.appNODE_ENV=production
heroku config:set MONGO_URI="mongodb+srv://..."
heroku config:set JWT_SECRET="your-secret-key"
heroku config:set CLIENT_URL="https://your-frontend.vercel.app"
heroku config:set NODE_ENV="production"BREVO_API_KEY=<your_brevo_api_key>BREVO_SENDER_EMAIL=[email protected](must be validated in Brevo)BREVO_SENDER_NAME=Contact Form
Note: Many hosts block raw SMTP ports. Using Brevo's HTTP API avoids SMTP restrictions and is recommended for reliability.
-
VITE_API_BASEincludes/apiat the end - Backend URL is HTTPS (not HTTP) for production
- Backend is already deployed and running
-
MONGO_URIconnection string is valid - MongoDB Atlas IP whitelist includes 0.0.0.0/0 (or your host's IPs)
-
JWT_SECRETis strong and unique (min 32 characters) -
CLIENT_URLmatches your frontend domain exactly - All special characters in passwords are URL-encoded if needed
- Frontend can reach backend (check Network tab in browser)
- No CORS errors in browser console
- Can successfully register and login
- MongoDB shows new documents being created
- Never commit .env files to version control
- Use different secrets for development and production
- Rotate JWT secrets periodically in production
- Use strong passwords for MongoDB users (min 16 characters)
- Enable 2FA on MongoDB Atlas and hosting platforms
- Monitor access logs regularly
- Keep dependencies updated (
npm audit fix)
If your password contains special characters, URL-encode them:
@→%40:→%3A/→%2F?→%3F#→%23%→%25
Example:
Password: p@ss:word/123
Encoded: p%40ss%3Aword%2F123
Frontend (Browser Console):
console.log(import.meta.env.VITE_API_BASE);Backend (Node.js):
console.log("MONGO_URI:", process.env.MONGO_URI ? "Set" : "Not Set");
console.log("JWT_SECRET:", process.env.JWT_SECRET ? "Set" : "Not Set");| Variable | Location | Required | Example |
|---|---|---|---|
VITE_API_BASE |
Frontend | Yes | https://backend.com/api |
MONGO_URI |
Backend | Yes | mongodb+srv://... |
JWT_SECRET |
Backend | Yes | random-64-char-string |
CLIENT_URL |
Backend | Yes | https://frontend.com |
CLIENT_URLS |
Backend | No | https://a.com,https://b.com |
PORT |
Backend | No* | 5000 |
NODE_ENV |
Backend | Yes | production |
*Usually auto-set by hosting platform