Prerequisites
Before starting, ensure you have the required tools installed:Node.js
Version: 22.x or higherDownload Node.js
Yarn
Package Manager: Yarn (Yarn Berry)Install Yarn
Spectra Server uses Yarn Berry (v4.7.0) via Corepack. The
packageManager field in package.json ensures the correct version is used.Setup Steps
Clone the Repository
Clone the Spectra Server repository from GitHub:Navigate to the project directory:
Install Dependencies
Install all required Node.js packages using Yarn:This will install:
- Production dependencies (Express, Socket.IO, etc.)
- Development dependencies (TypeScript, ESLint, tsx, etc.)
- Optional dependencies for WebSocket performance optimization
Generate SSL Certificates (Optional)
For local HTTPS/WSS testing, generate self-signed certificates:This creates:
keys/server.key- Private key (4096-bit RSA)keys/server.crt- Self-signed certificate (valid for 10 years)
Configure Environment Variables
Create a Edit the
.env file from the example template:.env file to match your setup:If you haven’t generated SSL certificates, set
INSECURE=true to run the server without TLS.Start the Development Server
Run the server in development mode with hot-reload:The server will start with:
- Port 5100 - Incoming WebSocket server (client connections)
- Port 5101 - REST API server (status, previews, etc.)
- Port 5200 - Outgoing WebSocket server (overlay/observer connections)
Available Scripts
Spectra Server provides several npm scripts for development and testing:Development Scripts
Start development server - Runs
yarn dev with hot-reload using tsx watch modeDevelopment mode - Uses
tsx watch ./src/index.ts for automatic restart on file changesSingle run mode - Starts the server once using
tsx ./src/index.ts (no watch mode)Build Scripts
Compile TypeScript - Transpiles TypeScript to JavaScript using
tscCode Quality Scripts
Run ESLint - Checks code for style and potential errors
Fix ESLint issues - Automatically fixes auto-fixable linting problems
Format with Prettier - Formats all source files according to Prettier rules
Replay Scripts
For testing with recorded match data:Replay match data - Runs the replay utility for testing
Instant replay - Replays match data as fast as possible (no delays)
Delayed replay - Replays match data with artificial delays
Timestamp replay - Replays using original timestamps from recorded data
Manual replay - Step through replay events manually
Custom file replay - Replay a specific game file:
yarn replay_file -- -game customGameTest.replayDevelopment Workflow
Hot Reload Development
Theyarn dev command uses tsx watch to monitor file changes:
src/ directory will automatically restart the server.
Testing API Endpoints
Once the server is running, test the REST API:Connecting with WebSocket Clients
Test WebSocket connectivity:Project Structure
Key directories and files:Troubleshooting
Port already in use
Port already in use
If ports 5100, 5101, or 5200 are already in use:
SSL certificate errors
SSL certificate errors
If you encounter SSL/TLS errors:
-
Verify certificate files exist:
-
Set
INSECURE=truein.envfor development -
Regenerate certificates if corrupted:
Module not found errors
Module not found errors
If you see module import errors:
TypeScript compilation errors
TypeScript compilation errors
Ensure you’re using the correct TypeScript version:
Next Steps
Configuration
Learn about all environment variables and configuration options
Docker Deployment
Deploy with Docker for production environments