node-fetch-timeout

1.0.2 • Public • Published

Welcome to node-fetch-timeout 👋

Version Version Documentation License: ISC Twitter: karankraina

A light-weight wrapper package built on awesome node-fetch package that adds timeout and retry option.

🏠 Homepage

Install

npm install node-fetch-timeout

Usage

Using require

const { request } = require('node-fetch-timeout);

Using ES6 Modules

import { request } from 'node-fetch-timeout';

Using Promise Chain

request(url, {
    ...standardRequestHeaders,
    timeout: 1, // timeout in milliseconds
    retryCount: 3 // number of retires - defaults to 1
  }).then(res => {
      // res is raw response
      // use res.json() or res.text()
      console.log(res);
  }).catch(err => { 
      console.log(err); 
  });

Using Latest Async/Await Syntax

try {
    const res = await request(url, {
        ...standardRequestHeaders,
        timeout: 1, // timeout in milliseconds
        retryCount: 3 // number of retires - defaults to 1
    });
    // res is raw response
    // use res.json() or res.text()
    console.log(res)
} catch (error) {
    console.log(error)
}

Author

👤 Karan Raina karanraina1996@gmail.com

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

Dependents (0)

Package Sidebar

Install

npm i node-fetch-timeout

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

19.4 kB

Total Files

7

Last publish

Collaborators

  • karankraina