You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Node.js includes a built-in `fetch()` implementation powered by undici starting from Node.js v18. However, there are important differences between using the built-in fetch and installing undici as a separate module.
51
+
52
+
### Built-in Fetch (Node.js v18+)
53
+
54
+
Node.js's built-in fetch is powered by a bundled version of undici:
const { statusCode, body } =awaitrequest('https://api.example.com/data');
152
+
constdata=awaitbody.json();
153
+
```
154
+
155
+
### Version Compatibility
156
+
157
+
You can check which version of undici is bundled with your Node.js version:
158
+
159
+
```js
160
+
console.log(process.versions.undici);
161
+
```
162
+
163
+
Installing undici as a module allows you to use a newer version than what's bundled with Node.js, giving you access to the latest features and performance improvements.
164
+
46
165
## Quick Start
47
166
48
167
```js
@@ -63,6 +182,44 @@ for await (const data of body) { console.log('data', data) }
63
182
console.log('trailers', trailers)
64
183
```
65
184
185
+
## Global Installation
186
+
187
+
Undici provides an `install()` function to add all WHATWG fetch classes to `globalThis`, making them available globally:
188
+
189
+
```js
190
+
import { install } from'undici'
191
+
192
+
// Install all WHATWG fetch classes globally
193
+
install()
194
+
195
+
// Now you can use fetch classes globally without importing
Copy file name to clipboardExpand all lines: deps/undici/src/docs/docs/api/CacheStore.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,9 @@ The `MemoryCacheStore` stores the responses in-memory.
13
13
14
14
**Options**
15
15
16
-
-`maxSize` - The maximum total size in bytes of all stored responses. Default `Infinity`.
17
-
-`maxCount` - The maximum amount of responses to store. Default `Infinity`.
18
-
-`maxEntrySize` - The maximum size in bytes that a response's body can be. If a response's body is greater than or equal to this, the response will not be cached. Default `Infinity`.
16
+
-`maxSize` - The maximum total size in bytes of all stored responses. Default `104857600` (100MB).
17
+
-`maxCount` - The maximum amount of responses to store. Default `1024`.
18
+
-`maxEntrySize` - The maximum size in bytes that a response's body can be. If a response's body is greater than or equal to this, the response will not be cached. Default `5242880` (5MB).
0 commit comments