Deno LandDeno

Deploy Docs

File system API

Deno Deploy supports a limited set of file system APIs available in Deno. Your project should be linked to a GitHub repository in order to use these APIs. URL deployments do not support these APIs and will result in an exception when used.

Deno.cwd

Deno.cwd() returns the current working directory of your deployment. It is located at the root of your GitHub repository and contains all files from your source repository.

Deno.readDir

Deno.readDir() allows you to list the contents of the linked GitHub repository.

The function is fully compatible with Deno.

function Deno.readDir(path: string | URL): AsyncIterable<DirEntry>

The path can be a relative or absolute. It can also be a file: URL.

Example

addEventListener("fetch", async (event) => {
  // List the posts in the `blog` directory located at the root
  // of the repository.
  const posts = [];
  for await (const post of Deno.readDir(`${Deno.cwd()}/blog`)) {
    posts.push(post);
  }

  // Return JSON.
  event.respondWith(
    new Response(JSON.stringify(posts, null, 2), {
      headers: {
        "content-type": "application/json",
      },
    }),
  );
});

Deno.readFile

Deno.readFile() allows you to read the contents of the linked GitHub repository.

The function definition is similar to Deno, but it doesn't support ReadFileOptions for the time being. Support will be added in the future.

function Deno.readFile(path: string | URL): Promise<Uint8Array>

The path can be a relative or absolute. It can also be a file: URL.

Note: At the moment, you can only read files that are less than 10 MB in size.

Example

addEventListener("fetch", async (event) => {
  // Let's read the README.md file available at the root
  // of the repository to explore the available methods.

  // Relative paths are relative to the root of the repository
  const readmeRelative = await Deno.readFile("./README.md");
  // Absolute paths.
  // The content of the repository is available under at Deno.cwd().
  const readmeAbsolute = await Deno.readFile(`${Deno.cwd()}/README.md`);
  // File URLs are also supported.
  const readmeFileUrl = await Deno.readFile(
    new URL(`file://${Deno.cwd()}/README.md`),
  );

  // Decode the Uint8Array as string.
  const readme = new TextDecoder().decode(readmeRelative);
  event.respondWith(new Response(readme));
});

Deno.readTextFile

This function is similar to Deno.readFile except it decodes the Uint8Array as a string (utf-8).

function Deno.readTextFile(path: string | URL): Promise<string>

Example

addEventListener("fetch", async (event) => {
  const readme = await Deno.readTextFile("./README.md");
  event.respondWith(new Response(readme));
});

Please file an issue in our feedback repository if you find any problem in Deploy service or documentation.