Building a Multiplayer UNO Game with Node.js and Socket.IO
Card games look simple until you try to put one online. Friends in different cities need to play the same hand, someone's phone drops off Wi-Fi mid-turn, and a modified browser could easily lie about what cards it holds. I built UNO Ultimate, a web-based UNO game, to deal with exactly those problems: you can play against the computer or with friends anywhere by sharing a link.
Why I built it
I wanted a UNO game that did not need an account or an install, and that I could change freely. Official versions fix the rules; house rules vary from family to family. I wanted the lobby to let a group agree on the rules, and I wanted new modes and themes to be a small code change rather than a rewrite. The project is written in JavaScript, HTML and CSS, and it started in late September 2026.
What it does
- Single player: play against 1 to 9 computer opponents.
- Multiplayer: 2 to 10 seats per room. You share the link, and empty seats can be filled with computer players.
- Game modes: Classic UNO, UNO Flip, UNO Show 'em No Mercy, Liar's UNO, and Mega Draw (+15), which is a home-made mode I added as an example.
- Themes: Classic, Frozen, Ramayanam and Mahabharatam.
- House rules in the lobby: starting hand size, stacking draw cards, draw until you can play, 7-0 swapping, liar mode and a knock-out card limit.
- Custom cards: add something like Wild Draw +15 x4 from the lobby with no code changes.
- Reconnects: refresh or lose your connection and you return to your seat. A computer plays for a disconnected player after 15 seconds, so the table never stalls.
- Spectators and rematch: friends can choose Watch only or join a running game to follow along, and they can take an empty seat between games. When a game ends, any player can press Rematch to deal again with the same people.
Two of the modes are worth explaining. In No Mercy, draw cards stack, you draw until you can play, 7 swaps hands, 0 passes all hands, and anyone who reaches 25 cards is knocked out. In Liar's UNO, every card is played face-down while you announce what it is, and lying is allowed. The next player either believes you or calls LIAR. If you were lying you take the card back and draw 2; if the accusation was wrong, the accuser draws 2.
How it works
The server is a Node.js application (version 18 or newer) that serves the static front end and runs Socket.IO for real-time communication. The layout separates concerns clearly:
server/index.jsis the web server and Socket.IO entry point.server/rooms.jshandles rooms, invite codes, host controls, reconnects and bot timing.server/engine/game.jsis the rules engine.server/engine/bot.jsis the computer player AI.server/engine/cards.jsdefines card types and matching rules.server/variants/holds one file per game mode.public/contains the client:app.jsfor the UI,cards.jsfor rendering andthemes.jsfor theme definitions.
A server-authoritative engine
The most important decision was making the rules engine live on the server. Clients send intentions, such as playing a card, and the server decides whether that is legal and what happens next. Because players never run the rules themselves, they cannot cheat by editing the page. It also means the computer players use the same engine as humans, so a bot move goes through exactly the same validation as a human one.
Modes as data plus a small engine
Each game mode is a file that declares an id, name, description, default rules and a buildDeck() function that returns the list of cards. The engine understands a fixed vocabulary of card types: numbers, skip, reverse, draw +N, skip everyone, discard all, flip, wild, wild draw +N, wild reverse draw +N, colour roulette and wild draw colour. Any combination and any +N value works, which is why a +15 deck is just a different list. To add a mode you copy megadraw.js, change those fields and register it in server/variants/index.js. Only a card with a genuinely new effect needs a new case in resolvePlay() in game.js.
Themes
A theme is a block in public/js/themes.js: card colours and names, action-card names, the table cloth, the table edge and the printed card back. Copy a block, give it a new key, and it appears in the theme menus. A development gallery page at /dev/gallery.html shows every card type in every theme, which makes previewing changes quick.
Deployment
Socket.IO needs long-lived WebSocket connections and the rooms are held in memory, so a serverless platform such as Vercel is the wrong fit. The repository includes a render.yaml, so a Deploy to Render button can put a copy online with nothing to configure; Render checks a /health endpoint and pushes redeploy automatically. Any host that runs a normal Node.js server works too, including Railway and Fly.io. For a quick session, you can run the game locally and expose it with npx cloudflared tunnel --url http://localhost:3000, which prints a temporary public link while your computer is running. The trade-offs are honest ones: on the free tier the server sleeps when idle, so the first visit can take about 30 seconds, and a restart or redeploy ends games in progress because rooms live in memory.
What I learned
- Put authority in one place. Server-side rules removed a whole class of cheating and sync bugs, and made bots trivial to integrate.
- Design variation as data. A card vocabulary combined with per-mode deck lists let me ship five modes and user-defined cards without special cases everywhere.
- Plan for disconnects early. Reconnect-to-seat and a bot that takes over after 15 seconds make the game forgiving on mobile networks.
- Test rules by simulation.
tests/simulate.jsplays thousands of bot-only games in every mode to catch rule bugs, which finds edge cases that hand-written examples miss. It runs withnpm test. - Match the host to the protocol. Choosing where to deploy is an architecture question when you depend on WebSockets and in-memory state.
Conclusion
UNO Ultimate is a small project, but it covers a useful set of multiplayer fundamentals: an authoritative server, data-driven variants, reconnection handling and simulation testing. If you want to try it, clone the repository, run npm install and npm start, then open http://localhost:3000. Anyone on the same Wi-Fi can join using the address the terminal prints.