Skip to main content
No breaking changes are expected, but additional features will be implemented soon.

Overview

Edge Scripting supports the Node.js file system API through the node:fs and node:fs/promises modules, so you can read, write, and manipulate files and directories from inside an Edge Script. The implementation sits on Deno’s sandboxed environment with Node.js compatibility. Both the Promise-based API (node:fs/promises) and the older callback-based API (node:fs) work. We recommend the Promise-based one for the cleaner async/await syntax.

Virtual file system

Every script gets a virtual file system for file operations. It lives in the virtual memory available to the worker. The directory tree currently has two folders:
You can create directories anywhere. Permissions are enforced for the owner (user) but not for group or others. All files are opened in w+.
Avoid creating directories in the root directory /. We plan to add folders there for other functions, such as /dev/* and other read only directories.
Paths in the virtual file system are limited to 4096 characters (foo/bar counts as 7) and to 48 segments (a/b/c is 3 segments). Capacity checks for creating, copying and moving happen before the operation runs. Copying a large file can therefore fail with an out of memory error even though there is still space to create new files or directories.

Importing the module

EdgeScripting supports both the Promise-based API and the callback-based API.

Callback-based API

Limitations

The file system runs in a sandbox, which constrains what it can do. The following sections cover where it differs from Node.js.
Always handle file system errors gracefully. The sandboxed environment may behave differently from traditional Node.js environments.
Symbolic links are supported. symlink(), symlinkSync(), readlink(), readlinkSync(), and lstat() work as expected.
Hard links are not supported. link() and linkSync() will throw errors.

File statistics and timestamps

All Stats timestamp properties are supported and return correct values: Reliable Stats properties:
  • size - File size in bytes
  • isFile() - Check if entry is a file
  • isDirectory() - Check if entry is a directory
  • atime - Last access time
  • mtime - Last modification time
  • ctime - Last status change time
  • atimeMs, mtimeMs, ctimeMs - Millisecond timestamps
  • birthtime - File creation time

File and directory permissions

File and directory permissions are supported for the owner (user) bits. chmod() and chmodSync() work, and Stats.mode reflects the permissions you set. access() respects owner-level read, write, and execute bits.
Group and others permission bits are accepted but have no effect: the sandboxed environment always runs as the file owner (uid=1000, gid=1000), so only the user/owner bits matter.chown() and chownSync() are implemented for compatibility, but ownership is not enforced. Changing the uid or gid has no effect on file access or permissions.

File watching

File system watching is not supported.
The following operations are unavailable:
  • watch() - Watch for file changes
  • watchFile() - Poll for file changes
  • unwatchFile() - Stop watching
  • FSWatcher class
Workaround: Use polling with stat() if you need to detect changes, but be mindful of performance implications and CPU time limits.

Performance considerations

Memory limits: The whole Virtual FileSystem lives inside your script memory. The current file system limits of your script is set up to 64MB. Reading large files may cause memory exhaustion if you store it in memory. Leverage streaming to avoid allocating too much memory at a time.CPU time: File I/O counts toward the 30-second CPU time limit per request.Best practices:
  • Stream large files instead of reading entirely into memory
  • Clean up temporary files to avoid storage bloat
  • See Limits for more details on resource constraints

Quickstart

Common file system patterns in EdgeScripting.

Example 1: Reading a file

Example 2: Writing a file

Example 3: Working with directories

Example 4: Error handling patterns

Example 5: Using FileHandle for chunked reading

This script is not optimized. It shows how chunked reading works, so please don’t run anything like it in production.

References

Last modified on August 17, 2026