Skip to content

Commit 796410b

Browse files
committed
readme: server side usage
1 parent 90dded8 commit 796410b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ fetcher.configure({
125125
fetcher.use(logger)
126126
```
127127

128+
### Server Side Usage
129+
130+
This library can be used server side with [node-fetch](https://www.npmjs.com/package/node-fetch)
131+
132+
Node CommonJS setup
133+
```ts
134+
// install node-fetch v2
135+
npm install node-fetch@2
136+
npm install @types/node-fetch@2
137+
138+
// fetch-polyfill.ts
139+
import fetch, { Headers, Request, Response } from 'node-fetch'
140+
141+
if (!globalThis.fetch) {
142+
globalThis.fetch = fetch as any
143+
globalThis.Headers = Headers as any
144+
globalThis.Request = Request as any
145+
globalThis.Response = Response as any
146+
}
147+
148+
// index.ts
149+
import './fetch-polyfill'
150+
```
151+
128152
### Utility Types
129153

130154
- `OpArgType` - Infer argument type of an operation

0 commit comments

Comments
 (0)