Skip to content

File I/O

There is no direct access to the filesystem in Val Town. This allows us to deploy and scale your code quickly and efficiently. If you need to read files from within a val, you can via the Val Town API.

Docs

read-file.tsRun in Val Town ↗
import ValTown from "npm:@valtown/sdk";
const vt = new ValTown();
const val_id = "your-val-id-here";
const response = await vt.vals.files.getContent(val_id, {
path: "path/to/file.txt",
});
const content = await response.text();
console.log(content);

Docs

create-file.tsRun in Val Town ↗
import ValTown from "npm:@valtown/sdk";
const vt = new ValTown();
const val_id = "your-val-id-here";
const file = await vt.vals.files.create(val_id, {
path: "path",
type: "directory",
});

Docs

update-file.tsRun in Val Town ↗
import ValTown from "npm:@valtown/sdk";
const vt = new ValTown();
const val_id = "your-val-id-here";
const file = await vt.vals.files.update(val_id, {
path: "path/to/file.txt",
content: "New file content",
});

Docs

list-files.tsRun in Val Town ↗
import ValTown from "npm:@valtown/sdk";
const vt = new ValTown();
const val_id = "your-val-id-here";
const files = await Array.fromAsync(
vt.vals.files.retrieve(id, {
path: "",
recursive: true,
})
);