get-fastest-url

1.0.4 • Public • Published

Get Fastest Url

Test the speed of server endpoints

Returns the fastest endpoint, given an array of urls.

Installation

npm install

Testing

npm t

Example

const getFastestUrl = require('get-fastest-url');

(async () => {
  const { url, elapsedMS } = await getFastestUrl([
    'https://www.reddit.com/user/ScottRatigan/m/js_lounge/',
    'https://news.ycombinator.com/',
    'https://www.twitter.com'
  ])
  console.log(`The fastest url was ${url} responding in ${elapsedMS} ms.`)
})()

Produces the following output:

The fastest url was https://news.ycombinator.com/ responding in 147.266 ms.

Example with Custom Timeout (ms)

const getFastestUrl = require('get-fastest-url')
const fetchTimeoutMS = 2000

(async () => {
  const { url, elapsedMS } = await getFastestUrl([
    'https://www.reddit.com/user/ScottRatigan/m/js_lounge/',
    'https://news.ycombinator.com/',
    'https://www.twitter.com'
  ], fetchTimeoutMS)
  console.log(`The fastest url was ${url} responding in ${elapsedMS} ms.`)
})()

Notes

If no endpoint responds before the timeout, url defaults to the first in the array.

/get-fastest-url/

    Package Sidebar

    Install

    npm i get-fastest-url

    Weekly Downloads

    9

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    6.16 kB

    Total Files

    7

    Last publish

    Collaborators

    • scotte510