Overview
Edge Scripting provides support for the Node.js file system API through thenode:fs and node:fs/promises modules. This allows you to read, write, and
manipulate files and directories within your Edge Scripts.
The file system API is based on Deno’s sandboxed environment with Node.js
compatibility, supporting both the modern Promise-based API (node:fs/promises)
and the traditional callback-based API (node:fs).
We recommend using the Promise-based API for cleaner async/await syntax.
Virtual File System
Each script has now access to a Virtual File System that allow to handle file based operations. This file system lives on the Virtual Memory available of the worker. Currently the file directory is composed of two folder:w+.
We suggest you to avoid creating directory in root directory
/ as we are going
to create new folders with differents functions, like /dev/* and other read
only directories.foo/bar is 7 characters. It’s also limited to 48 segments (a/b/c is 3
segments).
Capacity checks for creating, copying and moving are done before the
operation. This can result in trying to copy a large file resulting in an out of
memory error, even though there is space left to create new files or
directories.
Importing the Module
EdgeScripting supports both the modern Promise-based API and the traditional callback-based API.Promise-based API (Recommended)
Callback-based API
Limitations
EdgeScripting’s file system implementation operates in a sandboxed environment with limitations. Understanding these constraints is essential for building reliable applications.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 - 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
Here are practical examples showing 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