Introduction
caution
This library is only compatible with Node.js v18+ and relies on the native Fetch API which is an experimental feature.
Getting Started
- Install Reliable Fetch using your favorite package manager.
- npm
- yarn
npm add --save-dev @hachibu/reliable-fetch
yarn add --dev @hachibu/reliable-fetch
- Create a file named
timeout.js
with the following code.
const reliableFetch = require('@hachibu/reliable-fetch').default
async function main() {
const timeout = 10 // milliseconds
await reliableFetch('https://google.com')
.on('timeout', () => console.log('timeout triggered'))
.timeout({ timeout })
.catch(console.log)
}
main()
- Finally, run the code.
node timeout.ts