Skip to content

Commit 3b6ac7e

Browse files
committed
📝 Update node-fetch code snippet
see #179
1 parent 96150f0 commit 3b6ac7e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,27 +226,28 @@ For older versions, the Node.js standard library does not provide a native imple
226226
_The non-global way (preferred):_
227227

228228
```javascript
229+
import fetch, { FormData } from "node-fetch"
230+
229231
// w is a reusable wretch instance
230232
const w = wretch().polyfills({
231-
fetch: require("node-fetch"),
232-
FormData: require("form-data"),
233-
URLSearchParams: require("url").URLSearchParams,
233+
fetch,
234+
FormData,
234235
});
235236
```
236237

237238
_Globally:_
238239

239240
```javascript
241+
import fetch, { FormData } from "node-fetch";
242+
240243
// Either mutate the global object…
241-
global.fetch = require("node-fetch");
242-
global.FormData = require("form-data");
243-
global.URLSearchParams = require("url").URLSearchParams;
244+
global.fetch = fetch;
245+
global.FormData = FormData;
244246

245247
// …or use the static wretch.polyfills method to impact every wretch instance created afterwards.
246248
wretch.polyfills({
247-
fetch: require("node-fetch"),
248-
FormData: require("form-data"),
249-
URLSearchParams: require("url").URLSearchParams,
249+
fetch,
250+
FormData,
250251
});
251252
```
252253

0 commit comments

Comments
 (0)