Skip to content

Commit a4fbd4d

Browse files
committed
fixup! fix C, format
1 parent 1ef8393 commit a4fbd4d

File tree

4 files changed

+146
-175
lines changed

4 files changed

+146
-175
lines changed

src/content/changelog/workers/2025-08-15-nodejs-fs.mdx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: The Node.js and Web File System APIs in Workers
33
description: The node:fs and Web File System APIs are now available in Workers.
44
products:
55
- workers
6-
date: 2025-08-15T01:00:00Z
6+
date: 2025-08-15
77
---
88

99
Implementations of the [`node:fs` module](https://nodejs.org/docs/latest/api/fs.html) and the [Web File System API](https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API) are now available in Workers.
@@ -17,22 +17,22 @@ The virtual file system is ephemeral with each individual request havig its own
1717
Workers running with the `nodejs_compat` compatibility flag will have access to the `node:fs` module by default when the compatibility date is set to `2025-09-01` or later. Support for the API can also be enabled using the `enable_nodejs_fs_module` compatibility flag together with the `nodejs_compat` flag. The `node:fs` module can be disabled using the `disable_nodejs_fs_module` compatibility flag.
1818

1919
```js
20-
import fs from 'node:fs';
20+
import fs from "node:fs";
2121

22-
const config = JSON.parse(fs.readFileSync('/bundle/config.json', 'utf-8'));
22+
const config = JSON.parse(fs.readFileSync("/bundle/config.json", "utf-8"));
2323

2424
export default {
25-
async fetch(request) {
25+
async fetch(request) {
2626
return new Response(`Config value: ${config.value}`);
27-
}
28-
}
27+
},
28+
};
2929
```
3030

3131
There are a number of initial limitations to the `node:fs` implementation:
3232

33-
* The glob APIs (e.g. `fs.globSync(...)`) are not implemented.
34-
* The file watching APIs (e.g. `fs.watch(...)`) are not implemented.
35-
* The file timestamps (modified time, access time, etc) are only partially supported. For now, these will always return the Unix epoch.
33+
- The glob APIs (e.g. `fs.globSync(...)`) are not implemented.
34+
- The file watching APIs (e.g. `fs.watch(...)`) are not implemented.
35+
- The file timestamps (modified time, access time, etc) are only partially supported. For now, these will always return the Unix epoch.
3636

3737
Refer to the [Node.js documentation](https://nodejs.org/docs/latest/api/fs.html) for more information on the `node:fs` module and its APIs.
3838

@@ -45,16 +45,16 @@ const root = navigator.storage.getDirectory();
4545

4646
export default {
4747
async fetch(request) {
48-
const tmp = await root.getDirectoryHandle('/tmp');
49-
const file = await tmp.getFileHandle('data.txt', { create: true });
48+
const tmp = await root.getDirectoryHandle("/tmp");
49+
const file = await tmp.getFileHandle("data.txt", { create: true });
5050
const writable = await file.createWritable();
51-
const writer = writable.getWriter();
52-
await writer.write('Hello, World!');
51+
const writer = writable.getWriter();
52+
await writer.write("Hello, World!");
5353
await writer.close();
5454

55-
return new Response('File written successfully!');
56-
}
57-
}
55+
return new Response("File written successfully!");
56+
},
57+
};
5858
```
5959

6060
As there are still some parts of the Web File System API tht are not fully standardized, there may be some differences between the Workers implementation and the implementations in browsers.

src/content/docs/workers/runtime-apis/nodejs/fs.mdx

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ pcx_content_type: configuration
33
title: fs
44
---
55

6-
import { Render, TypeScriptExample } from "~/components";
6+
import { Render } from "~/components";
77

8-
<Render file="nodejs-compat-howto" />
8+
<Render file="nodejs-compat-howto" product="workers" />
99

1010
You can use [`node:fs`](https://nodejs.org/api/fs.html) to access a virtual file
1111
system in Workers.
@@ -15,18 +15,16 @@ compatibility using the `nodejs_compat` compatibility flag. Any Worker
1515
running with `nodejs_compat` enabled and with a compatibility date of
1616
`2025-09-01` or later will have access to `node:fs` by default. It is
1717
also possible to enable `node:fs` on Workers with an earlier compatibility
18-
date using a comgination of the `nodejs_compat` and `enable_nodejs_fs_module`
18+
date using a combination of the `nodejs_compat` and `enable_nodejs_fs_module`
1919
flags. To disable `node:fs` you can set the `disable_nodejs_fs_module` flag.
2020

21-
<TypeScriptExample filename="index.ts">
22-
```ts
23-
import { readFileSync, writeFileSync } from 'node:fs';
21+
```js
22+
import { readFileSync, writeFileSync } from "node:fs";
2423

25-
const config = readFileSync('/bundle/config.txt', 'utf8');
24+
const config = readFileSync("/bundle/config.txt", "utf8");
2625

27-
writeFileSync('/tmp/abc.txt', 'Hello, world!');
26+
writeFileSync("/tmp/abc.txt", "Hello, world!");
2827
```
29-
</TypeScriptExample>
3028

3129
The Workers Virtual File System (VFS) is a memory-based file system that allows
3230
you to read modules included in your Worker bundle as read-only files, access a
@@ -37,35 +35,37 @@ directory for writing temporary files, or access common
3735
The directory structure initially looks like:
3836

3937
```
38+
4039
/bundle
41-
└── (one file for each module in your Worker bundle)
40+
└── (one file for each module in your Worker bundle)
4241
/tmp
43-
└── (empty, but you can write files, create directories, symlinks, etc)
42+
└── (empty, but you can write files, create directories, symlinks, etc)
4443
/dev
45-
├── null
46-
├── random
47-
├── full
48-
└── zero
44+
├── null
45+
├── random
46+
├── full
47+
└── zero
48+
4949
```
5050

5151
The `/bundle` directory contains the files for all modules included in your
5252
Worker bundle, which you can read using APIs like `readFileSync` or
5353
`read(...)`, etc. These are always read-only. Reading from the bundle
5454
can be useful when you need to read a config file or a template.
5555

56-
```javascript
57-
import { readFileSync } from 'node:fs';
56+
```js
57+
import { readFileSync } from "node:fs";
5858

5959
// The config.txt file would be included in your Worker bundle.
6060
// Refer to the Wrangler documentation for details on how to
6161
// include additional files.
62-
const config = readFileSync('/bundle/config.txt', 'utf8');
62+
const config = readFileSync("/bundle/config.txt", "utf8");
6363

6464
export default {
6565
async fetch(request) {
6666
return new Response(`Config contents: ${config}`);
6767
},
68-
}
68+
};
6969
```
7070

7171
The `/tmp` directory is writable, and you can use it to create temporary files
@@ -74,31 +74,31 @@ contents of `/tmp` are not persistent and are unique to each request. This means
7474
that files created in `/tmp` within the context of one request will not be
7575
available in other concurrent or subsequent requests.
7676

77-
```javascript
78-
import { writeFileSync, readFileSync } from 'node:fs';
77+
```js
78+
import { writeFileSync, readFileSync } from "node:fs";
7979

8080
export default {
81-
fetch(request) {
81+
fetch(request) {
8282
// The file `/tmp/hello.txt` will only exist for the duration
8383
// of this request.
84-
writeFileSync('/tmp/hello.txt', 'Hello, world!');
85-
const contents = readFileSync('/tmp/hello.txt', 'utf8');
84+
writeFileSync("/tmp/hello.txt", "Hello, world!");
85+
const contents = readFileSync("/tmp/hello.txt", "utf8");
8686
return new Response(`File contents: ${contents}`);
87-
}
88-
}
87+
},
88+
};
8989
```
9090

9191
The `/dev` directory contains common character devices:
9292

93-
* `/dev/null`: A null device that discards all data written to it and returns
93+
- `/dev/null`: A null device that discards all data written to it and returns
9494
EOF on read.
95-
* `/dev/random`: A device that provides random bytes on reads and discards all
96-
data written to it. Reading from `/dev/random` is only permitted when within
97-
the context of a request.
98-
* `/dev/full`: A device that always returns EOF on reads and discards all data
99-
written to it.
100-
* `/dev/zero`: A device that provides an infinite stream of zero bytes on reads
101-
and discards all data written to it.
95+
- `/dev/random`: A device that provides random bytes on reads and discards all
96+
data written to it. Reading from `/dev/random` is only permitted when within
97+
the context of a request.
98+
- `/dev/full`: A device that always returns EOF on reads and discards all data
99+
written to it.
100+
- `/dev/zero`: A device that provides an infinite stream of zero bytes on reads
101+
and discards all data written to it.
102102

103103
All operations on the VFS are synchronous. You can use the synchronous,
104104
asynchronous callback, or promise-based APIs provided by the `node:fs` module
@@ -115,26 +115,24 @@ exceed this limit, the Worker instance will be terminated and restarted.
115115

116116
The file system implementation has the following limits:
117117

118-
* The maximum total length of a file path is 4096 characters, including path
118+
- The maximum total length of a file path is 4096 characters, including path
119119
separators. Because paths are handled as file URLs internally, the limit
120-
accounts for percent-encoding of special characters, decoding characters
121-
that do not need encoding before the limit is checked. For example, the
122-
path `/tmp/abcde%66/ghi%zz' is 18 characters long because the `%66` does
123-
not need to be percent-encoded and is therefore counted as one character,
124-
while the `%zz` is an invalid percent-encoding that is counted as 3 characters.
125-
* The maximum number of path segments is 48. For example, the path `/a/b/c` is
120+
accounts for percent-encoding of special characters, decoding characters
121+
that do not need encoding before the limit is checked. For example, the
122+
path `/tmp/abcde%66/ghi%zz' is 18 characters long because the `%66`does
123+
not need to be percent-encoded and is therefore counted as one character,
124+
while the`%zz` is an invalid percent-encoding that is counted as 3 characters.
125+
- The maximum number of path segments is 48. For example, the path `/a/b/c` is
126126
3 segments.
127-
* The maximum size of an individual file is 128 MB total.
127+
- The maximum size of an individual file is 128 MB total.
128128

129129
The following `node:fs` APIs are not supported in Workers, or are only partially
130130
supported:
131131

132-
* `fs.watch` and `fs.watchFile` operations for watching for file changes.
133-
* The `fs.globSync()` and other glob APIs have not yet been implemented.
134-
* The `force` option in the `fs.rm` API has not yet bee implemented.
135-
* Timestamps for files are always set to the Unix epoch (`1970-01-01T00:00:00Z`).
136-
* File permissions and ownership are not supported.
137-
138-
:::
132+
- `fs.watch` and `fs.watchFile` operations for watching for file changes.
133+
- The `fs.globSync()` and other glob APIs have not yet been implemented.
134+
- The `force` option in the `fs.rm` API has not yet bee implemented.
135+
- Timestamps for files are always set to the Unix epoch (`1970-01-01T00:00:00Z`).
136+
- File permissions and ownership are not supported.
139137

140138
The full `node:fs` API is documented in the [Node.js documentation for `node:fs`](https://nodejs.org/api/fs.html).

0 commit comments

Comments
 (0)