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

heya-io-node

v1.3.0

Published

Intelligent I/O for Node

Downloads

43

Readme

io-node

Build status NPM version

Greenkeeper Dependencies devDependencies

This is a Node-specific transport for heya-io based on built-in http and https modules. The main purpose of the module is to provide an ergonomic simple light-weight HTTP I/O on Node leveraging existing customization facilities of heya-io where appropriate.

Following heya-io services are supported as is out of the box:

  • io.track — tracks I/O requests to eliminate duplicates, register an interest without initiating I/O requests, and much more.
  • io.mock — mocks responses to I/O requests without writing a special server courtesy of Mike Wilcox. Very useful for rapid prototyping and writing tests.
  • io.bust — a simple pseudo plugin to generate a randomized query value to bust cache.
  • io.retry — a flexible way to retry requests, e.g., to deal with unreliable servers or to watch for changing values.

Additionally it supports:

  • Completely transparent compression/decompression.
    • gzip and deflate are supported out of the box with no extra dependencies using built-in modules.
    • More compressions can be easily plugged in.
      • brotli is automatically supported if an underlying Node has it.
    • The compression is supported both ways.
  • Streaming.
    • Both streaming a server request and a server response are supported.

Examples

Plain vanilla GET:

const io = require('heya-io-node');

io.get('http://example.com/hello').then(function (value) {
  console.log(value);
});

io.get('/hello', {to: 'world', times: 5}).then(value => {
  // GET /hello?to=world&times=5
  console.log(value);
});

Some other verbs (REST example):

function done() { console.log('done'); }

io.post('/things', {name: 'Bob', age: 42}).then(done);
io.put('/things/5', {name: 'Alice', age: 33}).then(done);
io.patch('/things/7', {age: 14}).then(done);
io.remove('/things/3').then(done);

Streaming (since 1.1.0) + encoding a payload (since 1.2.0):

const ios = require('heya-io-node/stream');
fs.createReadStream('sample.json')
  .pipe(ios.post({
    url: 'https://example.com/analyze',
    headers: {
      'Content-Type': 'application/json',
      '$-Content-Encoding': 'gzip',
      'Accept: plain/text'
    }
  }))
  .pipe(process.stdout);

// or it can be done more granularly:

io.post({
  url: 'https://example.com/analyze',
  headers: {
    'Content-Type': 'application/json',
    '$-Content-Encoding': 'gzip',
    'Accept: plain/text'
  },
  responseType: '$tream'
}, fs.createReadStream('sample.json'))
.then(res => res.pipe(process.stdout));

Mock in action:

// set up a mock handler
io.mock('/a*', (options, prep) => {
  console.log('Got call: ' + options.method + ' ' + prep.url);
  return 42;
});

// let's make a call
io.get('/a/x').then(value => {
  console.log(value); // 42
});

// set up a redirect /b => /a/b
io.mock('/b', options => io.get('/a/b', options.query || options.data || null));

// let's make another call
io.get('/b', {q: 1}).then(value => console.log(value)); // 42

Using url template to sanitize URLs (ES6):

const url = require('heya-io/url');

const client = 'Bob & Jordan & Co';
io.get(url`/api/${client}/details`).then(value => {
  // GET /api/Bob%20%26%20Jordan%20%26%20Co/details
  console.log(value);
});

See more examples in heya-io's Wiki, heya-io-node's Wiki, and the cookbooks of heya-io:

How to install

npm install --save heya-io-node
# or: yarn add heya-io-node

Documentation

All documentation can be found in project's wiki.

Working on this project

In order to run tests locally, you should start the test server first:

npm start

Then (likely in a different command line window) run tests:

npm test

The server runs indefinitely, and can be stopped by Ctrl+C.

Versions

  • 1.3.0 Replaced obsolete url module with WHATWG URL.
  • 1.2.0 Fixed a bug with large UTF-8 documents, updated dependencies.
  • 1.1.7 Technical release: updated dependencies.
  • 1.1.6 Technical release: added Greenkeeper and removed yarn.lock.
  • 1.1.5 Updated dependencies and added a test suite for io.retry.
  • 1.1.4 Updated dependencies.
  • 1.1.3 Added experimental IncomeMessage support.
  • 1.1.2 Exposed getData() and getHeaders() on stream and error objects.
  • 1.1.1 Added support for Buffer, replaced failure objects with Error-based objects.
  • 1.1.0 Getting rid of request, use native http/https, support compression and streaming.
  • 1.0.3 Bugfix: custom headers. Thx Bryan Pease!
  • 1.0.2 Added custom body processors.
  • 1.0.1 New dependencies.
  • 1.0.0 The initial release.

License

BSD or AFL — your choice.