1.0.2 ā€¢ Published 2 years ago

node-fetch-timeout v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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