Skip to content

Commit

Permalink
📝 Update node-fetch code snippet
Browse files Browse the repository at this point in the history
see #179
  • Loading branch information
elbywan committed Apr 29, 2023
1 parent 96150f0 commit 00a7ee8
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,27 +226,28 @@ For older versions, the Node.js standard library does not provide a native imple
_The non-global way (preferred):_

```javascript
import fetch, { FormData } from 'node-fetch'

// w is a reusable wretch instance
const w = wretch().polyfills({
fetch: require("node-fetch"),
FormData: require("form-data"),
URLSearchParams: require("url").URLSearchParams,
fetch,
FormData,
});
```

_Globally:_

```javascript
import fetch, { FormData } from "node-fetch";

// Either mutate the global object…
global.fetch = require("node-fetch");
global.FormData = require("form-data");
global.URLSearchParams = require("url").URLSearchParams;
global.fetch = fetch;
global.FormData = FormData;

// …or use the static wretch.polyfills method to impact every wretch instance created afterwards.
wretch.polyfills({
fetch: require("node-fetch"),
FormData: require("form-data"),
URLSearchParams: require("url").URLSearchParams,
fetch,
FormData,
});
```

Expand Down

0 comments on commit 00a7ee8

Please sign in to comment.