Timeout HTTP/HTTPS requests


Keywords
http, https, timeout, get, url, uri, request, simple
License
MIT
Install
npm install timed-out@6.0.0

Documentation

timed-out Build Status

Timeout HTTP/HTTPS requests

Emits Error object with code property equal ETIMEDOUT or ESOCKETTIMEDOUT when ClientRequest is hanged.

Usage

const http = require('http');
const timedOut = require('timed-out');

const request = http.get('http://www.google.ru');
timedOut(request, 2000); // Sets a 2 seconds limit

API

timedout(request, time)

request

Required Type: ClientRequest

The request to watch.

time

Required Type: number | object

Time in milliseconds to wait for a connect event on the socket and also time to wait on inactive socket.

Or you can pass an object with the following fields:

  • connect - Time to wait for a connection.
  • socket - Time to wait for activity on the socket.

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.