Skip to content

Commit

Permalink
➖ Remove requirement for abort-controller package in node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
exah committed Nov 14, 2022
1 parent aabed5f commit 0dfc5c9
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 40 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,20 @@ await posts.delete(1).void() // → undefined

### Node.js Support

Install [`node-fetch`](https://github.com/node-fetch/node-fetch), [`abort-controller`](https://github.com/mysticatea/abort-controller) packages and setup them as globally available variables.
Install [`node-fetch`](https://github.com/node-fetch/node-fetch) and setup it as globally available variable.

```sh
yarn add node-fetch abort-controller
npm install --save node-fetch
```

```js
import fetch, { Headers, Request, Response, FormData } from 'node-fetch'
import AbortController from 'abort-controller'

globalThis.fetch = fetch
globalThis.Headers = Headers
globalThis.Request = Request
globalThis.Response = Response
globalThis.FormData = FormData
globalThis.AbortController = AbortController
```

> ⚠️ Please, note `node-fetch` v2 may hang on large response when using `.clone()` or response type shortcuts (like `.json()`) because of smaller buffer size (16 kB). Use v3 instead and override default value of 10mb when needed with [`highWaterMark`](https://github.com/node-fetch/node-fetch#custom-highwatermark) option.
Expand Down Expand Up @@ -632,8 +630,7 @@ function void(): Promise<void>
Sets `Accept: '*/*'` in `headers` and returns [`undefined`](http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined) after the request:

```ts
await instance.post('/posts', { title: 'Hello' })
// do something
const nothing = await instance.post('/posts', { title: 'Hello' }).void()
```

<details><summary>Same code with native <code>fetch</code></summary>
Expand Down
31 changes: 0 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
"@types/prettier": "^2.7.1",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"abort-controller": "^3.0.0",
"auto-changelog": "^2.4.0",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
Expand Down
2 changes: 0 additions & 2 deletions test.setup.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import fetch, { Headers, Request, Response, FormData } from 'node-fetch'
import AbortController from 'abort-controller'

globalThis.fetch = fetch
globalThis.Headers = Headers
globalThis.Request = Request
globalThis.Response = Response
globalThis.AbortController = AbortController
globalThis.FormData = FormData

0 comments on commit 0dfc5c9

Please sign in to comment.