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

@prodatalab/jszmq

v0.2.2

Published

Port of zeromq to Javascript over Web Socket transport

Readme

jszmq

jszmq is port of zeromq to Javascript, supporting both browsers and NodeJS. The library only support the WebSocket transport (ZWS 2.0).

The API of the library is similar to that of zeromq.js.

Compatibility with ZeroMQ

WebSocket transport added to zeromq recently, and it is only available when compiling from source.

Other ports of zeromq, like NetMQ (C#) and JeroMQ (Java) don't yet support the WebSocket transport.

Compatibility with ZWS 1.0, zwssock, JSMQ and NetMQ.WebSockets

The library is currently not compatible with ZWS 1.0 and the implementation of it.

Installation

npm install --save jszmq

Supported socket types

Following socket types are currently supported:

  • Pub
  • Sub
  • XPub
  • XSub
  • Dealer
  • Router
  • Req
  • Rep
  • Push
  • Pull

How to use

Import jszmq with one of the following:

import * as zmq from 'jszmq';
const zmq = require('jszmq');

Creating a socket

To create a socket you can either use the socket function, which is compatible with zeromq.js or use the socket type class.

Socket type class:

const dealer = new zmq.Dealer();

with socket function:

const dealer = zmq.socket('dealer');

Bind

To bind call the bind function:

const zmq = require('jszmq');

const router = new zmq.Router();
router.bind('ws://localhost:80');

You can also provide an http server and bind multiple sockets on the same port:

const http = require('http');
const zmq = require('jszmq');

const server = http.createServer();

const rep = new zmq.Rep();
const pub = new zmq.Pub();

rep.bind('ws://localhost:80/reqrep', server);
pub.bind('ws://localhost:80/pubsub', server);

server.listen(80);

bindSync function is an alias for bind in order to be compatible with zeromq.js.

Sending

To send call the send method and provide with either array or a single frame. Frame can either be Buffer of string, in case of string it would be converted to Buffer with utf8 encoding.

socket.send('Hello'); // Single frame
socket.send(['Hello', 'World']); // Multiple frames
socket.send([Buffer.from('Hello', 'utf8')]); // Using Buffer

Receiving

Socket emit messages through the on (and once) methods which listen to message event. Each frame is a parameter to the callback function, all frames are always instances of Buffer.

socket.on('message', msg => console.log(msg.toString())); // One frame
socket.on('message', (frame1, frame2) => console.log(frame1.toString(), frame2.toString())); // Multiple frames
socket.on('message', (...frames) => frames.forEach(f => console.log(f.toString()))); // All frames as array

Examples

Push/Pull

This example demonstrates how a producer pushes information onto a socket and how a worker pulls information from the socket.

producer.js

// producer.js
const zmq = require('jszmq'); // OR import * as zmq form 'jszmq'
const sock = zmq.socket('push'); // OR const sock = new zmq.Push();

sock.bind('tcp://127.0.0.1:3000');
console.log('Producer bound to port 3000');

setInterval(function(){
  console.log('sending work');
  sock.send('some work');
}, 500);

worker.js

// worker.js
const zmq = require('jszmq'); // OR import * as zmq form 'jszmq'
const sock = zmq.socket('pull'); // OR const sock = new zmq.Pull(); 

sock.connect('tcp://127.0.0.1:3000');
console.log('Worker connected to port 3000');

sock.on('message', function(msg) {
  console.log('work: %s', msg.toString());
});

Pub/Sub

This example demonstrates using jszmq in a classic Pub/Sub, Publisher/Subscriber, application.

Publisher: pubber.js

// pubber.js
const zmq = require('jszmq'); // OR import * as zmq form 'jszmq'
const sock = zmq.socket('pub'); // OR const sock = new zmq.Pub(); 

sock.bind('tcp://127.0.0.1:3000');
console.log('Publisher bound to port 3000');

setInterval(function() {
  console.log('sending a multipart message envelope');
  sock.send(['kitty cats', 'meow!']);
}, 500);

Subscriber: subber.js

// subber.js
const zmq = require('jszmq'); // OR import * as zmq form 'jszmq'
const sock = zmq.socket('sub'); // OR const sock = new zmq.Sub();

sock.connect('tcp://127.0.0.1:3000');
sock.subscribe('kitty cats');
console.log('Subscriber connected to port 3000');

sock.on('message', function(topic, message) {
  console.log('received a message related to:', topic.toString(), 'containing message:', message.toString());
});