README
@andycasen/withtimeout
Adds a timeout for promise based functions like the fetch API.
Install
$ npm install @andycasen/withtimeout --save
Usage
const fetch = require('node-fetch')
const withTimeout = require('@andycasen/withtimeout')
const myFetchUrl = 'https://myfetchurl.com'
const myTimeout = 3500 // Timeout in ms
withTimeout(fetch(myFetchUrl), myTimeout)
.then(data => data.json())
.then(data => {
// Do something with your data
})