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 🙏

© 2025 – Pkg Stats / Ryan Hefner

hydna

v2.0.3

Published

Hydna client

Downloads

23

Readme

Hydna for nodejs

The node.js hydna library is a straight-forward implementation of the wink binary protocol. The module has been closely modeled to the native node.js modules and the usage pattern should come naturally to developers using other node.js modules. The module does not have any external dependencies.

Creating a connection:

var hydna = require('hydna');
var channel = hydna.createChannel('localhost', 'rw');

channel.on('connect', function() {
  // read/write connection is ready to use 
});

channel.on('error', function() {
  // an error occured when connecting
});

A read/write channel is opened and event-listeners for connect and error are attached to the channel.

Sending Data:

var hydna = require('hydna');
var channel = hydna.createChannel('localhost', 'w');

channel.on('connect', function() {
  var message = 'Hello World!';
  channel.write(message, 'utf8');
});

Opens up a channel for writing and, when the connection has been established and the connect event has been emitted, writes a message.

Receiving data:

var hydna = require('hydna');
var channel = hydna.createChannel('localhost', 'r');

channel.setEncoding('utf8');

channel.on('data', function(data) {
  console.log(data);
});

Opens up a channel for reading and, when the data arrives and the data event is emitted, writes the received data to the console.

Installation

The easiest way to install this library is via npm:

$ npm install hydna

Test

The test suite requires a running server instance with the behaviors found test/behaviors loaded.

The default server address is testing.hydna.net. This can be overridden via the environment variable TEST_ADDRESS.

To run the test suite:

$  TEST_ADDRESS=<server_address_and_port> npm test 

API Specification

The node.js hydna client library consists of a single module — hydna — that contains everything that is necessary to communicate over hydna.

hydna.PAYLOAD_MAX_SIZE

Returns the maximum payload size.

hydna.origin=

Sets the origin identity that should be sent to the server on handshake.

hydna.agent=node-winsock-client/

Sets the agent identity that should be sent to the server on handshake.

hydna.send(url, data, [prio=0], [callback])

Send's a message to specified 'url' whithout creating a new hydna.Channel instance.

Note: This function is a complement to the ordinary Hydna Channel and should be used when a persistent connection is redundant.

hydna.dispatch(url, data, [callback])

Dispatch a signal on the specified 'url' whithout creating a new hydna.Channel instance.

Note: This function is a complement to the ordinary Hydna Channel and should be used when a persistent connection is redundant.

hydna.createChannel(url, mode, [options], [callback])

Opens a Channel to the specified ´'url'´.

This function is asynchronous. When the 'connect' event is emitted once connected. If there is a problem connecting, the 'connect' event will not be emitted, the 'error' event will be emitted with the exception.

Available modes:

  • read (r) - Open channel in read mode
  • write (w) - Open channel in write mode
  • readwrite (rw) - Open channel in read-write mode.
  • +emit(e) - Open channel with emit-signal support (e.g. 'rw+emit').

Available options:

  • disableMultiplex, disables multiplexing of channels over one socket. Default is false (multiplex is enabled),

This example opens a Channel and writes data too it. The same data is received :

var hydna = require('hydna');
var channel = hydna.createChannel('localhost', 'w');
channel.write('Hello World!');

hydna.Channel

This object is an abstraction of a TCP or UNIX socket. hydna.Channel instance implement a duplex stream interface. They can be created by the user and used as a client (with connect()) or they can be created by Node and passed to the user through the 'connection' event of a server.

hydna.Channel instances are EventEmitters with the following events:

Event: 'connect' function (data) { }

Emitted when a channel connection successfully is established. See connect(). The 'message' argument may or may not contain an initial message from server.

Event: 'data' function (data) { }

Emitted when data is received. The argument data will be a Buffer or String. Encoding of data is set by channel.setEncoding().

Event: 'drain' function () { }

Emitted when the write buffer becomes empty. Can be used to throttle uploads.

Event: 'error' function (exception) { }

Emitted when an error occurs. The 'close' event will be called directly following this event.

Event: 'close' function (had_error) { }

Emitted once the channel is fully closed. The argument had_error is a boolean which says if the channel was closed due to an error.

Event: 'signal' function (data) { }

Emitted when remote server send's a signal.

Channel.readable

Returns true if channel is readable, else false.

Channel.writable

Returns true if channel is writable, else false.

Channel.emitable

Returns true if channel is emitable, else false.

Channel.readyState

Either 'closed', 'closing', 'open', 'opening', 'read', 'write', 'readwrite' and/or '+emit'.

Channel.write(data, priority=0)

Sends data on the channel.

Returns ´true´ if the entire data was flushed successfully to the underlying connection. Returns false if all or part of the data was queued in user memory. ´'drain'´ will be emitted when the buffer is again free.

Channel.dispatch(data)

Dispatch a signal on the channel.

Returns ´true´ if the signal was flushed successfully to the underlying connection. Returns false if the all or part of the signal was queued in user memory. ´'drain'´ will be emitted when the buffer is again free.

Example:

var hydna = require('hydna');
var channel = hydna.createChannel('localhost', 'read+emit');
channel.on('signal', function(message) {
  if (message == 'pong') {
    console.log('Recevied pong from server');
  }
});
channel.dispatch('ping');

Channel.end([data])

Closes channel for reading, writing and emitting. The optional data is sent to the server.

Example:

var hydna = require('hydna');
var channel = hydna.createChannel('localhost', 'read');
channel.end('good bye!');

Channel.destroy()

Closes channel for reading, writing and emitting.

Examples

See directory "./examples" for different use-cases.