0Pricing
Edge Computing with Cloudflare Workers & Deno · Lesson

Developing Local Deno Apps

Build and run simple Deno applications locally, focusing on file I/O and network requests.

Developing Local Deno Apps is a free Edge Computing with Cloudflare Workers & Deno lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Edge Computing with Cloudflare Workers & Deno learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Your First Local Deno App

Welcome! In this lesson, we'll dive into building and running Deno applications right on your local machine.

Developing locally is crucial for testing and iterating quickly before deploying to the edge.

We'll focus on two fundamental operations: reading and writing files, and making network requests.

Hello, Deno!

Let's start with a classic "Hello, World!" program. Deno executes TypeScript or JavaScript directly.

Save this code as main.ts and run it using the deno run command in your terminal.

// main.ts
console.log("Hello from local Deno!");

Accessing Local Files

Deno has a secure permission model. To read files, you must explicitly grant permission using the --allow-read flag.

The Deno.readTextFile() function is an asynchronous way to read the content of a file as a string.

  • Deno.readTextFile(path): Reads a file.
  • --allow-read: Grants permission to read files.

Reading a Text File

Let's create a file named hello.txt with some content, then read it using Deno.

Remember to use the --allow-read flag when running this script!

// read_file.ts
// First, create a file named hello.txt with content like "Deno is awesome!"

async function readFileContent() {
  try {
    const filePath = "./hello.txt";
    const content = await Deno.readTextFile(filePath);
    console.log("File Content:", content);
  } catch (error) {
    console.error("Error reading file:", error.message);
  }
}

readFileContent();

Saving Data to Files

Just like reading, writing files also requires explicit permission: --allow-write.

The Deno.writeTextFile() function allows you to write a string to a file. It will create the file if it doesn't exist, or overwrite it if it does.

  • Deno.writeTextFile(path, data): Writes data to a file.
  • --allow-write: Grants permission to write files.

Writing to a Text File

Let's write some new content into a file. We'll create output.txt with a simple message.

Run this with deno run --allow-write write_file.ts.

// write_file.ts

async function writeFileContent() {
  try {
    const filePath = "./output.txt";
    const content = "This is new content written by Deno!";
    await Deno.writeTextFile(filePath, content);
    console.log("File written successfully to", filePath);
  } catch (error) {
    console.error("Error writing file:", error.message);
  }
}

writeFileContent();

Fetching Data from the Web

Deno includes a built-in fetch API, similar to browsers, for making HTTP requests.

To allow your Deno application to access the network, you need to use the --allow-net flag.

  • fetch(url): Initiates a network request.
  • --allow-net: Grants network access.

Getting Data from an API

Let's fetch some public data from a test API. We'll get a list of posts from JSONPlaceholder.

Run this with deno run --allow-net fetch_data.ts.

// fetch_data.ts

async function fetchData() {
  try {
    const response = await fetch("https://jsonplaceholder.typicode.com/posts/1");
    if (!response.ok) {
      throw new Error(`HTTP error! Status: ${response.status}`);
    }
    const data = await response.json();
    console.log("Fetched Data:", data);
  } catch (error) {
    console.error("Error fetching data:", error.message);
  }
}

fetchData();

Deno Permissions Check

Deno prioritizes security through explicit permissions. Which flag is needed to allow a Deno script to read a local file AND make an HTTP request?

Local Deno Apps Summary

Great job! You've learned how to build and run simple Deno applications locally.

  • We covered using deno run for executing scripts.
  • You practiced reading and writing files using Deno.readTextFile() and Deno.writeTextFile() with their respective --allow-read and --allow-write permissions.
  • You also fetched data from an external API using the fetch API and the --allow-net flag.

These are core skills for any Deno developer, setting you up for more complex applications, including those deployed to the edge!

Frequently asked questions

Is the “Developing Local Deno Apps” lesson free?

Yes — the full text of “Developing Local Deno Apps” is free to read here on the web, and the Edge Computing with Cloudflare Workers & Deno course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Edge Computing with Cloudflare Workers & Deno course, upgrade to CoddyKit PRO.

What will I learn in “Developing Local Deno Apps”?

Build and run simple Deno applications locally, focusing on file I/O and network requests. You practise Edge Computing with Cloudflare Workers & Deno with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Edge Computing with Cloudflare Workers & Deno?

No prior experience is required. Edge Computing with Cloudflare Workers & Deno on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Developing Local Deno Apps” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Edge Computing with Cloudflare Workers & Deno lesson?

Yes. Every Edge Computing with Cloudflare Workers & Deno lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Deno Runtime Essentials
  2. Module System & Permissions
  3. Developing Local Deno Apps
  4. Testing Deno Applications
← Back to Edge Computing with Cloudflare Workers & Deno