Build a dinosaur runner game with Deno, pt. 4
Part four of the Deno dino runner series adds score persistence: a leaderboard HTML page that polls an API every 30 seconds, a managed Prisma Postgres database provisioned in Deno Deploy, and Oak routes to submit and rank scores. It covers connecting locally via `deno run --tunnel` or a DATABASE_URL with sslmode=require, and a lazily created npm:pg connection pool that falls back across three sets of credential environment variables. The scores table gets a descending index on score and timestamp, created by a startup migration script, and rank is computed with a COUNT query after insert.
Related posts
- Build a dinosaur runner game with Deno, pt. 5
Deno mediumAdeptPart five of a Deno tutorial series adds player identity and customization to a browser dinosaur runner game. Plain DOM modals collect a player name and preferences for dino color, background theme and difficulty. The DinoGame class loads settings from the server or localStorage and applies theme gradients and difficulty speed multipliers (0.8/1.0/1.3). New PostgreSQL `players` and `player_settings` tables back Oak routes under `/api/customization`, which use INSERT ... ON CONFLICT upserts to persist those choices.
- Build a dinosaur runner game with Deno, pt. 3
Deno mediumAdeptPart 3 of a Deno tutorial series adds obstacles and collision detection to a canvas-based dinosaur runner game. Cactus obstacles spawn on a frame timer, move left at the game speed, and award points when they leave the screen. An axis-aligned bounding-box overlap check ends the run, and a difficulty level computed every 200 points raises speed and shortens the spawn interval down to a floor. The stage also adds a simple leg animation, a game-over overlay, high scores persisted in localStorage, and redeployment with `deno deploy`.
- Build a dinosaur runner game with Deno, pt. 6
Deno mediumAdeptThe final stage of the Deno dinosaur runner series adds observability using Deno Deploy's built-in logs, traces and metrics dashboards. A logging middleware emits one structured JSON line per HTTP request, and route handlers log business events like score submissions and customization saves. Custom OpenTelemetry spans wrap the leaderboard, score submission and customization routes, carrying attributes, events and recorded exceptions. Platform metrics (status codes, latency, CPU, memory, GC time, bandwidth) are used to spot anomalies before drilling into traces, and the `--tunnel` flag sends local telemetry to the same dashboards for verification before deploying.
- How to Build a CRUD API with Oak and Deno KV
Deno mediumAdeptDeno KV, a key-value database built into the Deno runtime, can back a simple CRUD API for users and addresses served by Oak's Router. The walkthrough models a secondary index on email as a separate key prefix that maps email to user ID. It uses kv.atomic() with .check() to keep the primary and index keys consistent under concurrent writes, and paginates kv.list() with limit and cursor. The code runs with the --unstable flag in Deno 1.33+ and is tested with curl.
- Persist Data in Deno with npm using Prisma, Mongoose, Apollo, and more.
Deno mediumAdeptDeno's npm: specifiers let you use popular data-layer packages directly, with Deno's opt-in permission flags limiting what a possibly compromised dependency can reach, such as environment variables holding database credentials. Three quick-start walkthroughs follow. Prisma is initialized against a Supabase PostgreSQL database and routed through Prisma Data Platform's Data Proxy. A Mongoose schema with validations writes to and reads from MongoDB. An Apollo GraphQL server defines typeDefs and resolvers over a static dataset.