Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ihfaz297/MND/llms.txt

Use this file to discover all available pages before exploring further.

Backend Environment Variables

The backend uses a .env file in the MND-backend/ directory.

Example .env File

# Google Distance Matrix API Key
# Get your key from: https://console.cloud.google.com/apis/credentials
GOOGLE_DM_API_KEY=your_api_key_here

# Server Configuration
PORT=3000
NODE_ENV=production

# JWT Secret for Auth Tokens (optional, auto-generated if not set)
JWT_SECRET=your_random_secret_key_here

# Email Configuration for Magic Links (optional)
EMAIL_FROM=noreply@yourdomain.com
EMAIL_SMTP_HOST=smtp.gmail.com
EMAIL_SMTP_PORT=587
EMAIL_SMTP_USER=your-email@gmail.com
EMAIL_SMTP_PASSWORD=your-app-password

Required Variables

GOOGLE_DM_API_KEY
string
required
Google Distance Matrix API key for calculating travel times and distances.How to get:
  1. Go to Google Cloud Console
  2. Enable Distance Matrix API
  3. Create credentials (API key)
  4. Restrict key to Distance Matrix API only
See Google APIs Setup for detailed instructions.

Server Configuration

PORT
number
default:"3000"
Port number the server listens on.Examples:
PORT=3000  # Default
PORT=8080  # Alternative
PORT=80    # HTTP (requires sudo)
NODE_ENV
string
default:"development"
Environment mode. Affects logging and error handling.Valid values:
  • development - Verbose logging, detailed errors
  • production - Minimal logging, sanitized errors
  • test - Test mode

Authentication (Optional)

The backend includes magic link authentication for user favorites.
JWT_SECRET
string
Secret key for signing JWT tokens. Auto-generated if not provided.Generate a secure secret:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
Example:
JWT_SECRET=a1b2c3d4e5f6789abcdef0123456789abcdef0123456789abcdef012345678

Email Configuration (Optional)

For sending magic link emails. If not configured, tokens are logged to console.
EMAIL_FROM
string
Sender email address for magic links.Example:
EMAIL_FROM=noreply@university.edu
EMAIL_SMTP_HOST
string
SMTP server hostname.Common providers:
  • Gmail: smtp.gmail.com
  • Outlook: smtp.office365.com
  • SendGrid: smtp.sendgrid.net
EMAIL_SMTP_PORT
number
SMTP server port.Standard ports:
  • 587 - TLS (recommended)
  • 465 - SSL
  • 25 - Unencrypted (not recommended)
EMAIL_SMTP_USER
string
SMTP authentication username (usually your email).
EMAIL_SMTP_PASSWORD
string
SMTP authentication password.For Gmail: Use an App Password, not your regular password.

Frontend Environment Variables

The React frontend uses Vite’s environment variable system.

Create .env File

Create .env in MND-frontend/:
# Backend API URL
VITE_API_BASE_URL=http://localhost:3000

# Google Maps API Key (for frontend maps, optional)
VITE_GOOGLE_MAPS_API_KEY=your_maps_api_key_here

Vite Environment Variables

Vite environment variables must be prefixed with VITE_ to be exposed to the client.
VITE_API_BASE_URL
string
required
Backend API base URL.Development:
VITE_API_BASE_URL=http://localhost:3000
Production (same server):
VITE_API_BASE_URL=/api  # Relative path
Production (separate server):
VITE_API_BASE_URL=https://api.yourdomain.com
VITE_GOOGLE_MAPS_API_KEY
string
Google Maps JavaScript API key for map display (optional).Note: This is different from the Distance Matrix API key. This key is exposed to clients, so restrict it to your domain.

Using Environment Variables in Code

In React components:
const apiUrl = import.meta.env.VITE_API_BASE_URL;
const mapsKey = import.meta.env.VITE_GOOGLE_MAPS_API_KEY;

Flutter Environment Variables

The Flutter app uses flutter_dotenv package.

Create .env File

Create .env in mnd_flutter/:
# Backend API URL
API_BASE_URL=http://192.168.1.100:3000

# Google Maps API Key (Android/iOS)
GOOGLE_MAPS_API_KEY=your_mobile_maps_api_key_here
API_BASE_URL
string
required
Backend API base URL.Local development (emulator):
# Android emulator
API_BASE_URL=http://10.0.2.2:3000

# iOS simulator
API_BASE_URL=http://localhost:3000
Local development (physical device):
API_BASE_URL=http://192.168.1.100:3000  # Your computer's network IP
Production:
API_BASE_URL=https://api.yourdomain.com
GOOGLE_MAPS_API_KEY
string
Google Maps API key for Android/iOS.Restrict this key to your app’s bundle ID/package name.

Using in Flutter Code

import 'package:flutter_dotenv/flutter_dotenv.dart';

final apiUrl = dotenv.env['API_BASE_URL'];
final mapsKey = dotenv.env['GOOGLE_MAPS_API_KEY'];

Load .env on Startup

In main.dart:
import 'package:flutter_dotenv/flutter_dotenv.dart';

void main() async {
  await dotenv.load(fileName: ".env");
  runApp(MyApp());
}

.env.example Template

Provide a template for other developers: MND-backend/.env.example:
# Copy this file to .env and fill in your values

# Google Distance Matrix API Key
GOOGLE_DM_API_KEY=your_api_key_here

# Server Configuration
PORT=3000
NODE_ENV=development

# Optional: Email for magic links
# EMAIL_FROM=noreply@example.com
# EMAIL_SMTP_HOST=smtp.gmail.com
# EMAIL_SMTP_PORT=587
# EMAIL_SMTP_USER=your-email@gmail.com
# EMAIL_SMTP_PASSWORD=your-app-password

Security Best Practices

Never commit .env files to version control!

Add to .gitignore

# Environment variables
.env
.env.local
.env.production
.env.development

Rotate API Keys

  • Rotate Google API keys every 90 days
  • Use different keys for development and production
  • Restrict keys to specific APIs and domains

Server-Side vs Client-Side

Server-side (backend .env):
  • Keys are never exposed to clients
  • Can contain sensitive secrets
  • Used for Distance Matrix API, email passwords, etc.
Client-side (Vite/Flutter .env):
  • Keys are exposed in compiled code
  • Must be restricted by domain/bundle ID
  • Only use for client-side APIs (Maps JavaScript API)

Environment-Specific Configuration

Create multiple environment files:
.env.development   # Local development
.env.staging       # Staging server
.env.production    # Production server
Load based on NODE_ENV:
import dotenv from 'dotenv';

const envFile = `.env.${process.env.NODE_ENV || 'development'}`;
dotenv.config({ path: envFile });

Verification

Test that environment variables are loaded:
# Backend
node -e "require('dotenv').config(); console.log(process.env.GOOGLE_DM_API_KEY)"

# Should output your API key (not 'undefined')

Next Steps

Build docs developers (and LLMs) love