npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nxtedition/undici

v1.0.0

Published

An HTTP/1.1 client, written from scratch for Node.js

Downloads

3

Readme

undici

Build
Status

An HTTP/1.1 client, written from scratch for Node.js.

Undici means eleven in Italian. 1.1 -> 11 -> Eleven -> Undici. It is also a Stranger Things reference.

Install

npm i undici

API

new undici.Client(url, opts)

A basic HTTP/1.1 client, mapped on top a single TCP/TLS connection. Keepalive is enabled by default, and it cannot be turned off.

The url will be used to extract the protocol and the domain/IP address. The path is discarded.

Options:

  • timeout, the timeout after which a request will time out, in milliseconds. Default: 30000 milliseconds.

  • pipelining, the amount of concurrent requests to be sent over the single TCP/TLS connection according to RFC7230. Default: 1.

client.request(opts, cb(err, data))

Performs an HTTP request.

Options:

  • path
  • method
  • body, it can be a String, a Buffer or a stream.Readable.
  • headers, an object with header-value pairs.

Headers are represented by an object like this:

{
  'content-length': '123',
  'content-type': 'text/plain',
  connection: 'keep-alive',
  host: 'mysite.com',
  accept: '*/*'
}

Keys are lowercased. Values are not modified. If you don't specify a host header, it will be derived from the url of the client instance.

The data parameter in the callback is defined as follow:

  • statusCode
  • headers
  • body, a stream.Readable with the body to read. A user must call data.body.resume()

Example:

const { Client } = require('undici')
const client = new Client(`http://localhost:3000`)

client.request({
  path: '/',
  method: 'GET'
}, function (err, data) {
  if (err) {
    // handle this in some way!
    return
  }
  const {
    statusCode,
    headers,
    body
  } = data


  console.log('response received', statusCode)
  console.log('headers', headers)

  body.setEncoding('utf8')
  body.on('data', console.log)

  client.close()
})

Promises and async await are supported as well!

const { statusCode, headers, body } = await client.request({
  path: '/',
  method: 'GET'
})

client.pipelining

Property to set the pipelining factor.

client.full

True if the number of requests waiting to be sent is greater than the pipelining factor. Keeping a client full ensures that once the inflight set of requests finishes there is a full batch ready to go.

client.close()

Close the client as soon as all the enqueued requests are completed

client.destroy(err)

Destroy the client abruptly with the given err. All the current and enqueued requests will error.

Events

  • 'drain', emitted when the queue is empty.

undici.Pool

A pool of Client connected to the same upstream target. A pool creates a fixed number of Client

Options:

  • connections, the number of clients to create. Default 100.
  • pipelining, the pipelining factor. Default 1.
  • timeout, the timeout for each request. Default 30000 milliseconds.

pool.request(req, cb)

Calls client.request(req, cb) on one of the clients.

pool.close()

Calls client.close() on all the clients.

pool.destroy()

Calls client.destroy() on all the clients.

License

MIT