[Collaboration] WebSocket Node Server — PM2 Guide

Guide for running the WebSocket-based real-time collaboration server with PM2.

The .js file required to run the server is provided separately. Contact tech support for the file and detailed instructions.

Runtime

  • Node.js v16.13.1

WebSocket Server & PM2

PM2 is recommended for process management. It keeps the Node.js application running and restarts it automatically on abnormal termination, while letting you run as a background process.

Install PM2

npm install pm2 -g

Start the Server

Windows

:: cmd (run as Administrator)
set HOST=<host>
set PORT=<port>
pm2 start collaboServer.js

:: Example
set HOST=58.161.1.23
set PORT=12000
pm2 start collaboServer.js
# PowerShell (run as Administrator)
$env:HOST=<host>
$env:PORT=<port>
pm2 start collaboServer.js

# Example
$env:HOST="58.161.1.23"
$env:PORT="12000"
pm2 start collaboServer.js

Linux

Run from the directory containing collaboServer.js, or pass the full path.

HOST=<host> PORT=<port> pm2 start collaboServer.js

# Examples
HOST=58.161.1.23 PORT=12000 pm2 start collaboServer.js
HOST=58.161.1.23 PORT=12000 pm2 start /home/abc/collaboServer/collaboServer.js
HOST=58.161.1.23 PORT=12000 pm2 start collaboServer/collaboServer.js

Verify the Server is Running

status: online means the server is up.

pm2 list

Stop the Server

# Kill
pm2 kill <filename>

# Delete from PM2
pm2 delete <filename>

Monitoring

Live monitor

pm2 monit

Log files

Stored under ./logs (relative to the server's working directory). Split per day plus a separate error log. Logs cover:

  • Server startup and status
  • Document create / delete and user connection info
  • WebSocket and Redis errors
  • Exceptions