Environment Variables
The backend uses environment variables for configuration. Create a.env file in the Backend/ directory based on .env.example.
Required Variables
Configuration Reference
Server Configuration
Server Configuration
PORT
- Type: Number
- Default:
3001 - Description: Port on which the server listens for HTTP connections
- Location:
server.js:13
- Type: String
- Values:
development,test,production - Default:
development - Description: Environment mode for the application
- Type: String
- Default:
* - Description: CORS origin policy. Use
*for LAN play, specific origins for production - Location:
server.js:34
- Type: Boolean
- Default:
false - Description: Enable/disable authentication routes and database features
- Location:
server.js:38
Database Configuration - PostgreSQL
Database Configuration - PostgreSQL
DB_HOST
- Type: String
- Default:
127.0.0.1 - Description: PostgreSQL server hostname or IP address
- Location:
config/db.js:20
- Type: Number
- Default:
5432 - Description: PostgreSQL server port
- Location:
config/db.js:21
- Type: String
- Default:
elemental - Description: Database name
- Location:
config/db.js:22
- Type: String
- Default:
postgres - Description: Database user for authentication
- Location:
config/db.js:23
- Type: String
- Default:
password - Description: Database password
- Location:
config/db.js:24
- Type: Boolean
- Default:
true - Description: Enable SSL for database connections (recommended for production)
- Location:
config/db.js:14
Database Configuration - SQLite
Database Configuration - SQLite
DB_USE_SQLITE
- Type: Boolean
- Default:
false - Description: Use SQLite in-memory database instead of PostgreSQL
- Location:
config/db.js:4
When
DB_USE_SQLITE=true, the application uses an in-memory SQLite database. This is perfect for:- Local development
- LAN play without external dependencies
- Quick testing
Security Configuration
Security Configuration
JWT_SECRET
- Type: String
- Required: Yes (if authentication is enabled)
- Description: Secret key for signing JWT authentication tokens
- Best Practice: Use a long, random string (minimum 32 characters)
Database Setup
Option 1: SQLite (Recommended for LAN)
For local/LAN play, SQLite provides a zero-configuration database:- No external database server required
- Perfect for LAN gameplay
- Zero configuration
- Fast and lightweight
config/db.js:7-12
Option 2: PostgreSQL (Production)
For production deployments with persistent data:Install PostgreSQL
Install PostgreSQL on your server or use a managed service like Heroku Postgres, AWS RDS, or Railway.
config/db.js:14-32
Server Configuration
Socket.IO Configuration
The server uses Socket.IO for real-time communication:server.js:58-59
CORS is set to
* to allow connections from any origin, which is necessary for LAN play where clients connect from different IP addresses.Network Binding
The server binds to all network interfaces to accept LAN connections:server.js:63
Authentication Routes
Authentication routes are conditionally loaded based on database availability:server.js:38-49
Configuration Files
config.js
Loads database configuration fromconfig.json and merges with environment variables:
config/config.js
config.json
Defines base database configuration with SSL settings:config/config.json