# Hosting a multiplayer Node game on Nimboki ## Publish the Node build Package the client, the bundled `server.mjs`, and this root `nimboki.json`. Set `min_schema_version` to the version returned when you create the characters table. Add an HTTP endpoint at `/health` that returns 2xx. Bind the server to `process.env.PORT`. ```json {"version":1,"runtime":"node","entry":"server.mjs","health_path":"/health","min_schema_version":1,"always_on":true} ``` For the Node server build, the upload limit is 32 MiB compressed, 96 MiB expanded, 24 MiB per file and 2,048 entries. A 12.5 MB ZIP is within the compressed limit. To validate a build locally, use `python -m nimboki pack BUILD_DIR --out game.zip`. To publish, set `NIMBOKI_URL` and your developer's `NIMBOKI_TOKEN` in the publishing terminal and run `python -m nimboki publish BUILD_DIR --project PROJECT_ID`. These settings belong to the CLI. For an MCP upload, call `runtime_guide` for the ZIP, `build_prepare` and `release_publish` steps. The Node runtime forwards same-origin WebSocket upgrades at `/ws` and supports long-lived sessions. A static project's custom socket path rejects the upgrade. A Node game has 96 bridge channels shared by HTTP requests and WebSockets, and each WebSocket message can carry up to 256 KiB. Sixty player sockets leave 36 channels for other requests. The gateway and runner terminate WebSocket control frames on their respective hops. An application message every 30 seconds can test the whole path. Reconnect after a release switch or interrupted connection. ## World lifetime and shutdown Players enter one active release backed by one Machine and one Node game process. During an update, a second candidate starts for its health check. It gains the game's write credential authority when it becomes active. Load authoritative records when serving the active game. An active-only API call during the candidate's health check will fail. `always_on: true` keeps the world running when empty and continues metering runtime. By default, open player sockets keep the Machine awake. After the last player leaves, 15 minutes without game traffic makes it eligible for the next maintenance check, normally within another 30 seconds. A new visit wakes it. The hosting budget can pause either mode. A restart recreates the world from durable saves. On an orderly stop, the runner sends Node `SIGTERM` and leaves the project API available for up to eight seconds while Node exits. During replacement, the old release keeps its write authority until its Machine stops. A four-second final save fits this window. Continue periodic saves for crashes, and rehearse the final flush with real character sizes. The provider Machine has one shared CPU and 512 MiB of memory. ## Verify the player on the WebSocket The SDK’s `signIn()` offers a game-specific password or the player's Nimboki account. Both methods return the same game profile for the same verified identity. In the browser, call `session()` from `/_playable/player-auth.js` after signing in. Send its `access_token` in the first application message over WSS. On the Node server, hold gameplay until this check succeeds and bind the returned `player_id` to the connection. ```js const api = new URL("/v1/games/" + process.env.PLAYABLE_PROJECT_ID + "/", process.env.PLAYABLE_API_URL); async function verifyPlayer(accessToken) { const response = await fetch(new URL("player/me", api), { headers: { Authorization: "Bearer " + accessToken } }); if (!response.ok) throw new Error("Player sign-in required"); return (await response.json()).player_id; } ``` The browser SDK renews the short-lived token when `session()` is called. Verify a fresh token on reconnect and reauthenticate long-lived sessions if continued sign-in is required. For records calls from Node, use the same API base with `Authorization: Bearer `. Nimboki supplies the project ID, local API URL and release-scoped credential. The game needs no developer key, external database credentials or outbound Internet access. ## Create and save characters Pass this change to `schema_apply` with the project ID, current `expected_version`, and an idempotency key. ```json { "op": "create_table", "table": "characters", "server_only": true, "max_per_owner": 4, "columns": { "name": {"type": "text", "unique_casefold": true}, "data": "json", "level": "integer", "duel_rating": "number", "created_at": "text", "updated_at": "text" } } ``` The game server and project owner can read and write this table. The database enforces name uniqueness across owners and the four-character limit within the create transaction. Validate a nonempty character name in the game. Store the original JSON and write its two numeric ranking values to the top-level columns in the same mutation. Each JSON field can hold up to 1 MiB of compact UTF-8 JSON. The Node API forwarder accepts up to 1 MiB for the entire request, including the surrounding JSON. POST JSON relative to the project API base. For any player operation, use the owner from the verified connection. Before updating a character, select its ID under that owner and use the revision you read. Forward only public leaderboard fields to browsers. | Operation | Endpoint | JSON body | | --- | --- | --- | | List characters | `records/characters/query` | `{"filters":{"owner_id":"PLAYER_ID"},"limit":4}` | | Create | `records/characters/mutate` | `{"operation":"create","owner_id":"PLAYER_ID","values":{"name":"Mira","data":{"level":1,"duel_rating":1000},"level":1,"duel_rating":1000},"idempotency_key":"CREATE_ID"}` | | Save | `records/characters/mutate` | `{"operation":"update","record_id":"ROW_ID","expected_revision":1,"values":{"data":{"level":2,"gold":9,"duel_rating":1005},"level":2,"duel_rating":1005,"updated_at":"2026-12-06T12:00:00Z"},"idempotency_key":"SAVE_ID"}` | | Top levels and personal rank | `records/characters/leaderboard` | `{"score":"level","fields":["name"],"limit":10,"record_id":"ROW_ID"}` | | Top duel ratings | `records/characters/leaderboard` | `{"score":"duel_rating","fields":["name"],"limit":10}` | Send the complete JSON value when replacing `data`. Use a fresh key for each eight-second save and the same key and payload when retrying it. Use the returned revision on the next save. A 409 on update requires reloading and reconciling changes. Sixty online players saving every eight seconds average 7.5 writes per second. Stagger saves and measure end-to-end latency with your build. Rankings sort by descending numeric score and then by row ID. When `record_id` is supplied, `count_above` counts strictly greater scores across the whole table, even when the row falls outside the returned page. Ties share rank `count_above + 1`. Null scores are unranked. ## Import Supabase characters 1. From your trusted Supabase export, join `characters.user_id` to the Auth user ID. Select the ID and confirmed email for each account. Omit passwords, password hashes, tokens and provider secrets. Resolve unconfirmed addresses, duplicate names and ambiguous account matches before import. 2. As the project owner, call the MCP tool `records_import` once per account with its characters. Use the original character ID as `record_id`. Preserve the entire JSON, original timestamps and the two numeric scores. Each call accepts up to 100 rows and commits them together. Reuse its idempotency key and payload after a lost response. Duplicate IDs, names, conflicting account mappings or a fifth character reject the call. 3. When the player verifies their email by code (including game password setup) or signs in with Google, Nimboki matches the verified address, preserving the mailbox spelling before the @ and ignoring domain case, and binds the imported rows to that game's player ID. The game sees only the project-scoped ID. A later sign-in by a different identity with the same address cannot claim those rows again. Existing Nimboki players keep their player ID and existing saves. If the combined characters exceed four, the player retains their current saves and the import stays under the owner ID from the receipt. Reconcile those rows with the player and have them sign in again. 4. Before cutover, pause writes at the source, reconcile counts and representative character IDs, and verify a returning player can load, save, disconnect and resume. Keep a recoverable export through the cutover. ```json { "project_id":"PROJECT_ID", "table":"characters", "idempotency_key":"import-account-42-v1", "source_owner_id":"SUPABASE_USER_UUID", "verified_email":"mira@example.org", "records":[{ "record_id":"ORIGINAL_CHARACTER_UUID", "values":{"name":"Mira","data":{"level":12,"gold":50,"duel_rating":1140}, "level":12,"duel_rating":1140, "created_at":"2026-01-10T12:00:00Z","updated_at":"2026-12-01T12:00:00Z"} }] } ``` For scripted imports, the same payload works at `POST /api/tools/records_import` on the Studio origin with a developer bearer credential on the importer's machine. Hosted identity and runtime services remain Nimboki's responsibility.