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.
Read a file
Section titled “Read a file”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);
Create a file
Section titled “Create a file”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",});
Update a file
Section titled “Update a file”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",});
List files
Section titled “List files”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, }));