Overview
Edge Scripting supports the Node.js file system API through thenode: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: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.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.Promise-based API (recommended)
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 and hard links
Symbolic links are supported.symlink(), symlinkSync(), readlink(), readlinkSync(), and lstat() work as expected.
File statistics and timestamps
AllStats timestamp properties are supported and return correct values:
Reliable Stats properties:
size- File size in bytesisFile()- Check if entry is a fileisDirectory()- Check if entry is a directoryatime- Last access timemtime- Last modification timectime- Last status change timeatimeMs,mtimeMs,ctimeMs- Millisecond timestampsbirthtime- 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. Workaround: Use polling withstat() 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
Example 6: Symbolic links
References
- Node.js File System Documentation - Complete Node.js fs module reference
- Node.js fs/promises API - Promise-based file system API
- Node.js FileHandle Class - Advanced file operations
- Node.js File System Flags - Available flags for file operations
- MDN File API - Web standard File interface
- MDN Blob - Binary data objects
- MDN TextEncoder - Encoding strings to bytes
- MDN TextDecoder - Decoding bytes to strings
- EdgeScripting Limits - Resource limits and quotas