node:fs
The node:fs module in Azion Runtime: what its read, write, and directory functions return or throw inside a deployed function.
The node:fs module is the Node.js file system API. Node.js applications use it for file input and output (I/O): reading, writing, updating, and deleting files and directories. In Azion Runtime, import fs from "node:fs" builds, but a deployed function cannot write files with it, and its fs object exposes 8 members.
Synchronous reads go to an in-memory file system that the build fills from the build.memoryFS setting of azion.config.js. A relative path resolves from the root, so ./hello.txt is read as /hello.txt. A path the build did not embed throws an ENOENT error.
Methods
The table lists what each call returns or throws in a deployed function, on paths the build did not embed:
| Call | Result in a deployed function |
|---|---|
fs.readFileSync('./hello.txt') | Throws Error: ENOENT: no such file or directory, fs.readFileSync call for path '/hello.txt'. |
fs.writeFileSync('/tmp/my-file.txt', 'x') | Throws Error: unsupported. A later fs.readFileSync of the same path throws ENOENT. |
fs.existsSync('/') | Returns false. |
fs.readFile('./hello.txt', callback) | Passes Error: missing storage annotation: readfile './hello.txt' to the callback. |
readFile('./hello.txt') from node:fs/promises | Rejects with Error: missing storage annotation: readfile './hello.txt'. |
writeFile('/tmp/my-file.txt', 'hello') from node:fs/promises | Rejects with Error: missing storage annotation. |
readdir('/') from node:fs/promises | Rejects with Error: missing storage annotation: readdir '/'. |
stat('/') from node:fs/promises | Rejects with Error: missing storage annotation: stat '/'. |