Skip to content

File System

Read and write files by mounting a host directory into the sandbox.

src/index.ts
import type { ExportedHandler } from "kyushu-types";
import { writeFileSync, readFileSync } from "node:fs";
export default {
async fetch() {
writeFileSync("/data/hello.txt", "Hello from Kyushu!");
const content = readFileSync("/data/hello.txt", "utf8");
return {
status: 200,
headers: { "content-type": "text/plain" },
body: content,
};
},
} satisfies ExportedHandler;

By default, the sandbox has no access to the host filesystem. Mount a directory to expose it to your worker.

kyushu.run.toml
[[mounts]]
host = "."
guest = "/"
writable = true

Try it

Build and run the worker with its config.

Terminal window
kyu build && kyu run kyushu.run.toml

Then send a request to test it.

Terminal window
curl http://localhost:5987