Skip to main content

Environment variables

Daily GeoGame uses environment variables to configure the application. Create a .env.local file in the root directory of your project:

Required variables

MONGODB_URI

The MongoDB connection string is the only required environment variable:
Never commit your .env.local file to version control. It should be listed in .gitignore.

MongoDB Atlas setup

Daily GeoGame uses MongoDB Atlas for data storage. Follow these steps to set up your database:
1

Create a MongoDB Atlas account

Sign up for a free account at MongoDB Atlas.
2

Create a new cluster

Create a new cluster (the free M0 tier is sufficient for development and small deployments).
3

Configure network access

Add your IP address to the IP Access List, or allow access from anywhere (0.0.0.0/0) for development.
For production, restrict access to specific IP addresses or use VPC peering.
4

Create database user

Create a database user with read and write permissions. Save the username and password.
5

Get connection string

Click “Connect” on your cluster, choose “Connect your application”, and copy the connection string. Replace <password> with your database user password.
6

Add to .env.local

Paste the connection string into your .env.local file:

MongoDB connection handling

The application handles MongoDB connections through app/lib/mongodb.ts:
If MONGODB_URI is missing, the application will log a warning but won’t crash. However, database-dependent features won’t work.

Next.js configuration

The Next.js configuration is minimal by default (next.config.ts):
You can customize this file to add:
  • Image optimization domains
  • Custom headers
  • Redirects and rewrites
  • Experimental features

TypeScript configuration

The project uses strict TypeScript settings (tsconfig.json):
Key features:
  • Strict mode enabled for better type safety
  • Path alias @/* for cleaner imports
  • ES2017 target for modern JavaScript features

Development vs production settings

Development

For local development:
.env.local
  • Use a separate development database
  • Allow broader network access (0.0.0.0/0)
  • Enable detailed error messages

Production

For production deployment:
  • Use a dedicated production database
  • Restrict network access to your deployment platform’s IP ranges
  • Use strong, unique passwords
  • Enable MongoDB Atlas monitoring and alerts
Consider using different MongoDB clusters for development and production to avoid accidental data corruption.

Environment variable validation

To ensure your environment is configured correctly:
  1. Start the development server
  2. Check the console for warnings:
    • WARN: Missing MONGODB_URI environment variable - Add the variable to .env.local
    • Failed to initialize MongoDB client - Check your connection string format

Next steps

After configuration, you can:
  • Start developing locally with pnpm dev
  • Proceed to Deployment when ready to go live