Installation
Requirements
- Node.js >= 20.9.0
- MySQL / MariaDB
- Redis — required for matchmaking / chat queues; optional if you only exercise HTTP. Enable Redis before using
MatchmakingDemo.
Install dependencies
bash
npm installEnvironment variables
Create .env.development (local) or .env.production in the server repo root. Load order is described in the Chinese Configuration page (first sections).
Minimal example below; replace your_* placeholders with your MySQL credentials and a strong secret.
| Variable | What it is |
|---|---|
NODE_ENV | Node environment. development selects .env.development and dev-oriented behaviour in src/config. |
PORT | Single port for HTTP + Colyseus WebSocket (default 2567 → http://localhost:2567, Swagger /api-docs, etc.). |
DB_HOST | MySQL / MariaDB host (localhost on your machine). |
DB_PORT | Database port (3306 for MySQL by default). |
DB_USERNAME / DB_PASSWORD | DB login; never commit real passwords. |
DB_DATABASE | Database schema name (create the empty DB first). Entities/migrations: see project-structure docs (Chinese). |
JWT_SECRET | Symmetric secret used to sign access tokens (same tokens required by @RequireAuth() room options). Use a long random string in production. |
JWT_EXPIRES_IN | Access-token lifetime string (1h, 24h, …) passed to jsonwebtoken expiresIn. Refresh tokens / JWT_REFRESH_*: see “Redis 与 JWT” in Configuration. |
Redis, DB_TYPE, DB_SYNCHRONIZE, and the rest are listed in Configuration.
env
NODE_ENV=development
PORT=2567
DB_HOST=localhost
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=your_password
DB_DATABASE=your_database
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRES_IN=1hRun dev server
bash
npm run devVerify
Visit http://localhost:2567/api-docs and the static home page. For Colyseus rooms, follow Quick start step 3–4.
Translation status
The longest environment tables live in the Chinese configuration page: 配置说明 →.