惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 【当耐特】
小众软件
小众软件
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
Last Week in AI
Last Week in AI
H
Help Net Security
爱范儿
爱范儿
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
WordPress大学
WordPress大学
GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
腾讯CDC

Deno

Deno 2.8 | Deno Claw Patrol: an open-source security firewall for agents | Deno Fresh 2.3: Zero JS by default, View Transitions, and Temporal support | Deno Deno 2.7: Temporal API, Windows ARM, and npm overrides | Deno Build a dinosaur runner game with Deno, pt. 6 | Deno Build a dinosaur runner game with Deno, pt. 5 | Deno Deno Deploy is Generally Available | Deno Introducing Deno Sandbox | Deno Build a dinosaur runner game with Deno, pt. 4 | Deno Build a dinosaur runner game with Deno, pt. 3 | Deno Build a dinosaur runner game with Deno, pt. 2 | Deno React / Next.js Denial-of-Service Vulnerability: Deno Deploy users protected | Deno Deno 2.6: dx is the new npx | Deno React Server Functions / Next.js Vulnerability: Deno Deploy users protected | Deno My highlights from the new Deno Deploy | Deno Deno's Other Open Source Projects | Deno How Deno protects against npm exploits | Deno Help Us Raise $200k to Free JavaScript from Oracle | Deno Deno 2.5: Permissions in the config file | Deno Fresh 2.0 Graduates to Beta, Adds Vite Support | Deno Deno 2.4: deno bundle is back | Deno JavaScript™ Trademark Update | Deno What's coming to JavaScript | Deno A brief history of JavaScript | Deno Reports of Deno's Demise Have Been Greatly Exaggerated | Deno An Update on Fresh | Deno How Plaid migrated 100 services to a new database platform 5x faster with Deno | Deno Deno 2.3: Improved deno compile, local npm packages, and more | Deno Add JSR packages with pnpm and Yarn | Deno Zero-config Debugging with Deno and OpenTelemetry | Deno
Build a dinosaur runner game with Deno, pt. 1 | Deno
Jo Franchett · 2025-12-08 · via Deno

This series of blog posts will guide you through building a simple browser-based dinosaur runner game using Deno.

  1. Setup a basic project
  2. Game loop, canvas, and controls
  3. Obstacles and collision detection
  4. Databases and global leaderboards
  5. Player profiles, customization, and live tuning
  6. Observability, metrics, and alerting

The first thing we’ll need in order to build a browser-based game is a web server to serve our static files (HTML, CSS, JS). In Stage 1, we will set up a basic Deno project that serves these files locally and we’ll deploy it to the web with Deno Deploy.

Keep reading and build along or view the entire source here.

What You’ll Learn

  • Setting up a basic Deno project
  • Configuring and running the project
  • Creating a local server
  • Adding routes
  • Deploying to Deno Deploy

Setting up a basic deno project

Setting up a basic Deno project is straightforward. We can use the deno init command to create a new project folder with a deno.json configuration file.

This will set you up with a new directory called dino-runner containing a deno.json file where you can define tasks and configurations for your Deno project.

We’re going to build out a basic server that serves static files from a public/ directory and will serve API requests in later stages.

Set up the following structure in your new project, create empty files as needed, we’ll fill them in as we go:

Project Structure

Runner Game/
├── src/                    # Server-side source code
│   ├── main.ts             # Server entry point
│   └── routes/             # Route definitions
│       └── api.routes.ts   # API route definitions
├── public/                 # Client-side static files
│   ├── index.html          # Main landing page & game canvas
│   ├── js/
│   │   └── game.js         # Client-side game logic
│   └── css/
│       └── styles.css      # Styling
├── deno.json               # Deno configuration
└── .env                    # Environment variables

Project Configuration

First up, we’ll install the packages that we’ll need to use in this project. Firstly we’ll need the Oak framework to help us set up the server.

Then we’ll add some tasks to our deno.json file to help us run the server easily. In your deno.json, overwrite the tasks section with the following:

deno.json

"tasks": {
  "dev": "deno run --allow-net --allow-read --allow-env --env-file --watch src/main.ts",
  "start": "deno run --allow-net --allow-read --allow-env --env-file src/main.ts"
},
  • These tasks will allow us to run the server in development mode with file watching (deno task dev) and in production mode without watching (deno task start).
  • The --allow-net and --allow-read flags are necessary to allow the server to listen for network requests and read static files from the filesystem. Deno keeps your project secure by default, so you need to explicitly grant these permissions to allow the code access to these sensitive APIs.
  • The --env-file flag allows the server to access a .env file, which is useful for configuring the host and port and other variables we’ll need later on.

Lets set up some environment variables in our newly created .env file at the root the project folder:

.env

PORT=8000
HOST=localhost

Basic HTML

Next we’ll set up a basic index.html file in the public/ folder with links to the assets we’ll use later:

public/index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link
      rel="preload"
      href="https://demo-styles.deno.deno.net/fonts/Moranga-Regular.woff2"
      as="font"
      type="font/woff2"
      crossorigin
    />
    <link
      rel="preload"
      href="https://demo-styles.deno.deno.net/fonts/Moranga-Medium.woff2"
      as="font"
      type="font/woff2"
      crossorigin
    />
    <link
      rel="preload"
      href="https://demo-styles.deno.deno.net/fonts/Recursive_Variable.woff2"
      as="font"
      type="font/woff2"
      crossorigin
    />
    <link
      rel="stylesheet"
      href="https://demo-styles.deno.deno.net/styles.css"
    />
    <link rel="stylesheet" href="css/styles.css" />
    <link rel="icon" href="favicon.ico" type="image/x-icon" />
    <title>Dino Runner</title>
  </head>
  <body>
    <h1>Dino Runner Game - Stage 1</h1>
    <p>This is a placeholder for the Dino Runner game.</p>
    <script src="js/game.js" type="module"></script>
  </body>
</html>

The Server (src/main.ts)

We’ll create a very simple server using the Oak framework to serve static files from the public/ directory.

src/main.ts

import { Application } from "@oak/oak/application";

const PORT = parseInt(Deno.env.get("PORT") || "8001");
const HOST = Deno.env.get("HOST") || "localhost";

const app = new Application();


app.use(async (context, next) => {
  try {
    await context.send({
      root: `${Deno.cwd()}/public`,
      index: "index.html",
    });
  } catch {
    await next();
  }
});

app.listen({
  port: PORT,
});

console.log(`Server is running on http://${HOST}:${PORT}`);

This code spins up a local HTTP server that maps incoming requests directly to your /public folder. Deno.cwd() gets the current working directory, ensuring that the server correctly locates the public/ folder regardless of where the script is run from.

You should now be able to run the server locally with:

This should show you a very basic web page when you navigate to http://localhost:8000 in your browser:

Screenshot of initial web page

Adding routes (src/routes/api.routes.ts)

Next, we’ll set up a basic routing structure for our API endpoints. For now, this file will be mostly empty, but it sets the stage for future development.

src/routes/api.routes.ts

import { Router } from "@oak/oak/router";

export const apiRouter = new Router({ prefix: "/api" });


apiRouter.get("/health", (ctx) => {
  ctx.response.body = {
    status: "ok",
    message: "🦕 Stage 1 - Dino server is healthy!",
  };
});

This sets up a simple health check endpoint at /api/health that we can use to verify that our server is running correctly.

Then we’ll update the main server file to use this router. First, add an import for the router at the top of src/main.ts:

src/main.ts

import { apiRouter } from "./routes/api.routes.ts";

Then, after the app.use for static files, add the following:

src/main.ts


app.use(apiRouter.routes());
app.use(apiRouter.allowedMethods());

This tells the Oak application to use the routes defined in apiRouter.

Now, when you run the server, you can check the health endpoint by navigating to http://localhost:8000/api/health:

Screenshot of initial web page

Deploying to Deno Deploy

Let’s deploy your new project to Deno Deploy, so that you can share it with the world!

First, make sure you have a Deno Deploy account. If you don’t have one, you can sign up at https://console.deno.com/.

Then, you can use the deno deploy command to deploy your project:

This command will guide you through the deployment process. It will ask you to select a project name and will upload your code to Deno Deploy. Make sure to select “Edit app config” and set the entry point for your application to src/main.ts:

Setting entry point in app config

Once the deployment is complete, you’ll receive a URL where your application is live.

Deploying from the terminal

You can visit this URL in your browser to see your basic HTML page ready to be developed into a dinosaur runner game!

What’s Next?

Stage 2 introduces enhanced features — more interactivity, more refined structure, and the beginnings of real game logic. We’ll publish it next week! Stay tuned.

What are you building with Deno? Let us know on Twitter, Bluesky, or Discord.