Node.js Server
The Node.js server provides both REST API endpoints and WebSocket support for real-time friend updates. This is the recommended server for production deployments due to its scalability and real-time capabilities.
Prerequisites
- Node.js 18+ installed
- npm (comes with Node.js)
- Access to terminal/command line
Quick Start (Local Development)
Step 1: Navigate to Server Folder
Go to .Server/websocket/ in your Unity project folder
Step 2: Install Dependencies
npm install
Step 3: Start the Server
npm start
Or for development with auto-reload:
npm run dev
Step 4: Verify Server is Running
Server runs at:
- REST API:
http://localhost:3001 - WebSocket:
ws://localhost:3001/ws
Configuration
Edit config.js to customize server behavior:
| Setting | Default | Description |
|---|---|---|
server.port | 3001 | HTTP/WebSocket port |
server.host | "0.0.0.0" | Host to bind to |
database.path | "./database/friends.db" | SQLite database path |
cors.allowedOrigins | ["*"] | CORS origins allowed |
userTable.enabled | false | Enable external user table |
REST API Endpoints
Authentication
POST
/api/authFriends
GET
/api/friendsPOST
/api/friends/:friendIdDELETE
/api/friends/:friendIdFriend Requests
GET
/api/friend-requestsPOST
/api/friend-requestsPUT
/api/friend-requests/:requestIdDELETE
/api/friend-requests/:requestIdBlocked Users
GET
/api/blocked-usersPOST
/api/blocked-usersDELETE
/api/blocked-users/:userIdRooms & Invitations
GET
/api/rooms/:userIdPOST
/api/roomsPUT
/api/rooms/:roomIdGET
/api/invitationsPOST
/api/invitationsDELETE
/api/invitations/:invitationIdProduction Deployment
Environment Variables
For production, use environment variables:
PORT- Server portHOST- Server hostDATABASE_PATH- Database file path
Hosting Options
- Railway - Easy Node.js deployment
- Render - Free tier available
- AWS Elastic Beanstalk - Enterprise scaling
- DigitalOcean App Platform - Simple deploys
- Heroku - Classic platform (now paid)
Production Checklist
- Use environment variables for configuration
- Set CORS to specific domains, not "*"
- Use a process manager (PM2) for reliability
- Set up proper logging and monitoring
- Configure database backups
- Use HTTPS/WSS (reverse proxy with SSL)
Database
The Node.js server uses SQLite by default. The database file is created automatically on first run.
Database location: .Server/websocket/database/friends.db