Add multiplayer to your HTML5 game with WebSockets and Node.js

Transform any single-player HTML5 game into online multiplayer with Cerewro: a Node.js server with Socket.io syncs the game state in real time between all connected clients.

Multiplayer game architecture

ComponentTechnologyRole
ClientHTML5 Canvas + Socket.io-clientRenders game, sends inputs
ServerNode.js + Socket.ioState authority, syncs players
ProtocolWebSocket (via Socket.io)Real-time bidirectional communication
Cerewro Chat — Add multiplayer
Add online multiplayer to the Snake game:
- Node.js + Socket.io server on port 3001
- Waiting room with invite code
- Up to 4 simultaneous players, each with different color
- 20 ticks/second state sync
- When a snake collides it's eliminated (others continue)
- Winner: last snake surviving
- Real-time chat with Bootstrap
- Auto-reconnection on connection loss
server.js — Core server logic
const { Server } = require('socket.io');
const io = new Server(http.createServer(express()), { cors:{origin:'*'} });

io.on('connection', socket => {
  socket.on('createRoom', () => {
    const code = Math.random().toString(36).substr(2,6).toUpperCase();
    socket.join(code);
    socket.emit('roomCreated', { code });
  });

  socket.on('direction', ({ code, dir }) => {
    if (rooms[code]?.gameState?.snakes?.[socket.id])
      rooms[code].gameState.snakes[socket.id].nextDir = dir;
  });
});
Deploy on Railway or Render: The Node.js server needs to be on a real server for others to connect. Railway and Render offer free tiers for small projects. Ask Cerewro: "Deploy the game server on Railway with exact steps".