Skip to main content

Overview

BookMe uses environment variables for all configuration. This keeps sensitive data out of source code and allows easy configuration across different environments.

Quick Start

1

Copy the Example File

Create your .env file from the template:
cp .env.example .env
2

Edit Configuration

Open .env in your text editor and fill in the required values:
nano .env
# or
vim .env
3

Verify Configuration

Before running the server, ensure all required variables are set. The application will exit with an error if any required variable is missing.

Environment Variables Reference

Server Configuration

Controls HTTP server behavior and timeouts.
PORT=8080
SERVER_READ_TIMEOUT=15s
SERVER_WRITE_TIMEOUT=15s
SERVER_IDLE_TIMEOUT=60s
LOG_LEVEL=info
VariableRequiredDefaultDescription
PORTNo8080Port number for the HTTP server
SERVER_READ_TIMEOUTNo15sMaximum duration for reading request
SERVER_WRITE_TIMEOUTNo15sMaximum duration for writing response
SERVER_IDLE_TIMEOUTNo60sMaximum duration for idle keep-alive connections
LOG_LEVELNoinfoLogging level: debug, info, warn, error
Timeout values must be valid Go duration strings (e.g., 15s, 1m, 500ms).

Application Configuration

Core application settings.
ENV=dev
DB_URL=postgres://username:password@localhost:5432/bookme?sslmode=disable
VariableRequiredDefaultDescription
ENVNodevEnvironment mode: dev, staging, or production
DB_URLYes-PostgreSQL connection string
In production, always use sslmode=require in your DB_URL for secure database connections.

Authentication & Security

JWT and session secrets for authentication.
SESSION_SECRET=your-session-secret-here
JWT_SECRET=your-jwt-secret-here
VariableRequiredDescription
SESSION_SECRETYesSecret key for session encryption
JWT_SECRETYesSecret key for JWT token signing

Generating Secure Secrets

Use OpenSSL to generate cryptographically secure secrets:
openssl rand -base64 32
Run this command twice to generate both secrets:
# Generate SESSION_SECRET
SESSION_SECRET=$(openssl rand -base64 32)
echo "SESSION_SECRET=$SESSION_SECRET"

# Generate JWT_SECRET
JWT_SECRET=$(openssl rand -base64 32)
echo "JWT_SECRET=$JWT_SECRET"
Never commit your .env file to version control. It contains sensitive credentials.

OAuth Configuration

42 Intra OAuth settings. See OAuth Setup for detailed configuration.
CLIENT_ID=your-42-client-id
SECRET=your-42-client-secret
REDIRECT_URI=http://localhost:8080/oauth/callback
OAUTH_AUTH_URI=https://api.intra.42.fr/oauth/authorize
OAUTH_TOKEN_URI=https://api.intra.42.fr/oauth/token
REDIRECT_TOKEN_URI=http://localhost:3000/auth/callback
USER_INFO_URL=https://api.intra.42.fr/v2/me
VariableRequiredDescription
CLIENT_IDYes42 OAuth application client ID
SECRETYes42 OAuth application client secret
REDIRECT_URIYesBackend OAuth callback URL
OAUTH_AUTH_URIYes42 OAuth authorization endpoint
OAUTH_TOKEN_URIYes42 OAuth token endpoint
REDIRECT_TOKEN_URIYesFrontend redirect URL after authentication
USER_INFO_URLYes42 API endpoint for user information

Email Configuration

SMTP settings for email notifications. See Email Configuration for provider-specific setup.
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=[email protected]
SMTP_PASSWORD=your-smtp-password
FROM_EMAIL=[email protected]
FROM_NAME=BookMe
SMTP_USE_TLS=true
VariableRequiredDefaultDescription
SMTP_HOSTYes-SMTP server hostname
SMTP_PORTNo587SMTP server port
SMTP_USERNAMEYes-SMTP authentication username
SMTP_PASSWORDYes-SMTP authentication password
FROM_EMAILYes-Email address shown as sender
FROM_NAMENoBookMeDisplay name for sender
SMTP_USE_TLSNotrueEnable TLS encryption

Google Calendar Configuration

Optional Google Calendar integration for staff bookings. See Google Calendar Setup.
GOOGLE_CREDENTIALS_FILE=assets/book-me-service-account.json
GOOGLE_CALENDAR_SCOPE=https://www.googleapis.com/auth/calendar
GOOGLE_CALENDAR_ID=[email protected]
VariableRequiredDescription
GOOGLE_CREDENTIALS_FILEYes*Path to service account JSON file
GOOGLE_CALENDAR_SCOPEYes*Google Calendar API scope
GOOGLE_CALENDAR_IDYes*Google Calendar ID to sync with
*Required only if you want to enable Google Calendar integration for staff members.

Configuration Loading

The application loads configuration in the following order:
  1. Reads .env file from the project root (if it exists)
  2. Loads system environment variables
  3. Validates required variables
  4. Applies default values for optional variables
System environment variables take precedence over .env file values. This is useful for containerized deployments.

Environment-Specific Configuration

Development

ENV=dev
PORT=8080
LOG_LEVEL=debug
DB_URL=postgres://bookme:password@localhost:5432/bookme?sslmode=disable

Production

ENV=production
PORT=8080
LOG_LEVEL=warn
DB_URL=postgres://bookme:[email protected]:5432/bookme?sslmode=require
SMTP_USE_TLS=true
Production environments should always use:
  • Strong, randomly generated secrets
  • SSL/TLS for database connections (sslmode=require)
  • Secure SMTP with TLS enabled
  • Appropriate log levels (info or warn)

Troubleshooting

Missing Required Variables

If you see an error like:
required environment variable not set key=DB_URL
Ensure the variable is set in your .env file or system environment.

Invalid Duration Format

If timeout values are invalid:
invalid int environment variable, using default
Use valid Go duration strings: 15s, 1m, 500ms, etc.

File Not Found

If you see:
no .env file found, relying on system environment variables
This is a warning, not an error. The application will use system environment variables instead.

Next Steps

After configuring your environment:
  1. Set up your database
  2. Configure OAuth authentication
  3. Set up email notifications

Build docs developers (and LLMs) love