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:

SettingDefaultDescription
server.port3001HTTP/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.enabledfalseEnable external user table

REST API Endpoints

Authentication

POST /api/auth

Friends

GET /api/friends
POST /api/friends/:friendId
DELETE /api/friends/:friendId

Friend Requests

GET /api/friend-requests
POST /api/friend-requests
PUT /api/friend-requests/:requestId
DELETE /api/friend-requests/:requestId

Blocked Users

GET /api/blocked-users
POST /api/blocked-users
DELETE /api/blocked-users/:userId

Rooms & Invitations

GET /api/rooms/:userId
POST /api/rooms
PUT /api/rooms/:roomId
GET /api/invitations
POST /api/invitations
DELETE /api/invitations/:invitationId

Production Deployment

Environment Variables

For production, use environment variables:

  • PORT - Server port
  • HOST - Server host
  • DATABASE_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