Your codebase has been successfully configured to easily switch between development and production environments.
- ✅
server.js- Updated CORS and Socket.io to useCLIENT_URLenvironment variable - ✅
config/passportConfig.js- Updated OAuth callback URLs to useSERVER_URLenvironment variable - ✅
routes/authRoutes.js- Updated OAuth redirect URLs to useCLIENT_URLenvironment variable - ✅
package.json- Added convenientdevandstartscripts - ✅
.gitignore- Updated to ignore all environment files
- ✅
env.template- Template showing all required environment variables
- ✅
config/api.js- Centralized API configuration using environment variables
- ✅
app/login/page.js - ✅
app/signup/page.js - ✅
app/productivity/page.js - ✅
components/TaskList.js - ✅
components/TaskManager.js - ✅
components/TaskCard.js - ✅
components/FriendsProductivity.js - ✅
components/LockInTimer.js - ✅
components/apitest.js - ✅
components/SearchUser/FriendSearch.js - ✅
components/OpenAITaskCreator/AIModal.js - ✅
components/CurrentUserProductivity/UserProductivity.js - ✅
.gitignore- Updated to ignore environment files - ✅
package.json- Updated scripts
- ✅
env.template- Template for client environment variables
- ✅
package.json- Addeddev,setup, and improved scripts
- ✅
ENVIRONMENT_SETUP.md- Complete setup documentation - ✅
QUICK_REFERENCE.md- Quick command reference - ✅
SETUP_SUMMARY.md- This file
Run this command from the project root:
npm run setupThis creates:
server/.env.localclient/.env.local
Edit server/.env.local:
NODE_ENV=development
PORT=8080
MONGO_URI=mongodb://localhost:27017/taskstars
JWT_SECRET=your-dev-secret-key
CLIENT_URL=http://localhost:3000
SERVER_URL=http://localhost:8080
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret
OPENAI_API_KEY=your-openai-keyEdit client/.env.local:
NEXT_PUBLIC_API_URL=http://localhost:8080
NEXT_PUBLIC_SOCKET_URL=http://localhost:8080npm run devThis will start both the server and client in development mode.
Create server/.env.production:
NODE_ENV=production
PORT=8080
MONGO_URI=your-mongodb-atlas-uri
JWT_SECRET=strong-production-secret
CLIENT_URL=https://taskstars.onrender.com
SERVER_URL=https://taskstars.onrender.com
GOOGLE_CLIENT_ID=your-prod-google-client-id
GOOGLE_CLIENT_SECRET=your-prod-google-client-secret
GITHUB_CLIENT_ID=your-prod-github-client-id
GITHUB_CLIENT_SECRET=your-prod-github-client-secret
OPENAI_API_KEY=your-openai-keyCreate client/.env.production:
NEXT_PUBLIC_API_URL=https://taskstars.onrender.com
NEXT_PUBLIC_SOCKET_URL=https://taskstars.onrender.comnpm run build
npm start| Command | Description |
|---|---|
npm run setup |
Create initial .env.local files from templates |
npm run dev |
Run in development mode (both server & client) |
npm run build |
Build production client |
npm start |
Run in production mode |
npm run server:dev |
Run only server in dev mode |
npm run client:dev |
Run only client in dev mode |
| Variable | Purpose | Example |
|---|---|---|
NODE_ENV |
Environment mode | development or production |
PORT |
Server port | 8080 |
MONGO_URI |
Database connection | mongodb://localhost:27017/taskstars |
JWT_SECRET |
JWT signing secret | Random string |
CLIENT_URL |
Frontend URL (for CORS) | http://localhost:3000 |
SERVER_URL |
Backend URL (for OAuth) | http://localhost:8080 |
GOOGLE_CLIENT_ID |
Google OAuth ID | From Google Cloud Console |
GOOGLE_CLIENT_SECRET |
Google OAuth Secret | From Google Cloud Console |
GITHUB_CLIENT_ID |
GitHub OAuth ID | From GitHub Settings |
GITHUB_CLIENT_SECRET |
GitHub OAuth Secret | From GitHub Settings |
OPENAI_API_KEY |
OpenAI API key | From OpenAI dashboard |
| Variable | Purpose | Example |
|---|---|---|
NEXT_PUBLIC_API_URL |
Backend API URL | http://localhost:8080 |
NEXT_PUBLIC_SOCKET_URL |
WebSocket URL | http://localhost:8080 |
Note: Next.js requires
NEXT_PUBLIC_prefix for variables used in browser code.
- Go to Google Cloud Console
- Create credentials (OAuth 2.0)
- Add authorized redirect URIs:
- Dev:
http://localhost:8080/api/auth/google/callback - Prod:
https://taskstars.onrender.com/api/auth/google/callback
- Dev:
- Go to GitHub Developer Settings
- Create OAuth App
- Add authorization callback URL:
- Dev:
http://localhost:8080/api/auth/github/callback - Prod:
https://taskstars.onrender.com/api/auth/github/callback
- Dev:
→ Check CLIENT_URL in server/.env.local matches your client URL
→ Verify SERVER_URL in server/.env.local matches the URL in OAuth provider settings
→ Ensure MongoDB is running (for local dev) and MONGO_URI is correct
→ Restart both server and client after changing .env files
→ Check NEXT_PUBLIC_API_URL in client/.env.local is correct
- ✅
.envfiles are in.gitignore - ✅ Never commit real credentials
- ✅ Use strong JWT secrets in production
- ✅ Use separate OAuth apps for dev/prod
- ✅ Keep production credentials secure
- ✅ Create your
.env.localfiles usingnpm run setup - ✅ Fill in your actual credentials and settings
- ✅ Set up OAuth apps in Google and GitHub
- ✅ Test with
npm run dev - ✅ When ready for production, create
.env.productionfiles - ✅ Deploy with confidence!
- See
ENVIRONMENT_SETUP.mdfor detailed documentation - See
QUICK_REFERENCE.mdfor command cheat sheet - Check the
env.templatefiles for variable examples
You're all set! 🚀 Your codebase can now easily switch between development and production environments.