{"id":19973226,"url":"https://github.com/zeromq/jszmq","last_synced_at":"2025-08-20T08:33:35.826Z","repository":{"id":35096783,"uuid":"206296117","full_name":"zeromq/jszmq","owner":"zeromq","description":"Javascript port of zeromq","archived":false,"fork":false,"pushed_at":"2023-01-06T12:24:13.000Z","size":232,"stargazers_count":79,"open_issues_count":23,"forks_count":23,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-12-05T23:51:33.372Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zeromq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-04T10:44:36.000Z","updated_at":"2024-11-23T01:26:38.000Z","dependencies_parsed_at":"2023-01-15T13:46:21.167Z","dependency_job_id":null,"html_url":"https://github.com/zeromq/jszmq","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeromq%2Fjszmq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeromq%2Fjszmq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeromq%2Fjszmq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeromq%2Fjszmq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeromq","download_url":"https://codeload.github.com/zeromq/jszmq/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230408171,"owners_count":18220974,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T03:10:41.965Z","updated_at":"2024-12-19T09:08:11.799Z","avatar_url":"https://github.com/zeromq.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"jszmq\n======\n\njszmq is port of zeromq to Javascript, supporting both browsers and NodeJS.\nThe library only support the WebSocket transport ([ZWS 2.0](https://rfc.zeromq.org/spec:45/ZWS/)).\n\nThe API of the library is similar to that of [zeromq.js](https://github.com/zeromq/zeromq.js).\n\n## Compatibility with ZeroMQ\n\nWebSocket transport added to [zeromq](https://github.com/zeromq/libzmq) recently, and it is only available when compiling from source.\n\nOther ports of zeromq, like NetMQ (C#) and JeroMQ (Java) don't yet support the WebSocket transport.\n\n## Compatibility with ZWS 1.0, zwssock, JSMQ and NetMQ.WebSockets\n\nThe library is currently not compatible with ZWS 1.0 and the implementation of it. \n\n## Installation\n\n```\nnpm install --save jszmq\n```\n\n## Supported socket types\n\nFollowing socket types are currently supported:\n* Pub\n* Sub\n* XPub\n* XSub\n* Dealer\n* Router\n* Req\n* Rep\n* Push\n* Pull\n\n## How to use\n\nImport jszmq with one of the following:\n\n```js\nimport * as zmq from 'jszmq';\n```\n\n```js\nconst zmq = require('jszmq');\n```\n\n### Creating a socket\n\nTo create a socket you can either use the `socket` function, which is compatible with zeromq.js or use the socket type class.\n\nSocket type class:\n\n```js\nconst dealer = new zmq.Dealer();\n```\n\nwith socket function:\n```js\nconst dealer = zmq.socket('dealer');\n```\n\n### Bind\n\nTo bind call the `bind` function:\n\n```js\nconst zmq = require('jszmq');\n\nconst router = new zmq.Router();\nrouter.bind('ws://localhost:80');\n```\n\nYou can also provide an http server and bind multiple sockets on the same port:\n\n```js\nconst http = require('http');\nconst zmq = require('jszmq');\n\nconst server = http.createServer();\n\nconst rep = new zmq.Rep();\nconst pub = new zmq.Pub();\n\nrep.bind('ws://localhost:80/reqrep', server);\npub.bind('ws://localhost:80/pubsub', server);\n\nserver.listen(80);\n```\n\n`bindSync` function is an alias for bind in order to be compatible with zeromq.js.\n\n### Sending \n\nTo send call the send method and provide with either array or a single frame.\nFrame can either be Buffer of string, in case of string it would be converted to Buffer with utf8 encoding.\n\n```js\nsocket.send('Hello'); // Single frame\nsocket.send(['Hello', 'World']); // Multiple frames\nsocket.send([Buffer.from('Hello', 'utf8')]); // Using Buffer\n```\n\n### Receiving\n\nSocket emit messages through the on (and once) methods which listen to `message` event.\nEach frame is a parameter to the callback function, all frames are always instances of Buffer.\n\n```js\nsocket.on('message', msg =\u003e console.log(msg.toString())); // One frame\nsocket.on('message', (frame1, frame2) =\u003e console.log(frame1.toString(), frame2.toString())); // Multiple frames\nsocket.on('message', (...frames) =\u003e frames.forEach(f =\u003e console.log(f.toString()))); // All frames as array\n```\n\n## Examples\n\n### Push/Pull\n\nThis example demonstrates how a producer pushes information onto a\nsocket and how a worker pulls information from the socket.\n\n**producer.js**\n\n```js\n// producer.js\nconst zmq = require('jszmq'); // OR import * as zmq form 'jszmq'\nconst sock = zmq.socket('push'); // OR const sock = new zmq.Push();\n\nsock.bind('tcp://127.0.0.1:3000');\nconsole.log('Producer bound to port 3000');\n\nsetInterval(function(){\n  console.log('sending work');\n  sock.send('some work');\n}, 500);\n```\n\n**worker.js**\n\n```js\n// worker.js\nconst zmq = require('jszmq'); // OR import * as zmq form 'jszmq'\nconst sock = zmq.socket('pull'); // OR const sock = new zmq.Pull(); \n\nsock.connect('tcp://127.0.0.1:3000');\nconsole.log('Worker connected to port 3000');\n\nsock.on('message', function(msg) {\n  console.log('work: %s', msg.toString());\n});\n```\n\n### Pub/Sub\n\nThis example demonstrates using `jszmq` in a classic Pub/Sub,\nPublisher/Subscriber, application.\n\n**Publisher: pubber.js**\n\n```js\n// pubber.js\nconst zmq = require('jszmq'); // OR import * as zmq form 'jszmq'\nconst sock = zmq.socket('pub'); // OR const sock = new zmq.Pub(); \n\nsock.bind('tcp://127.0.0.1:3000');\nconsole.log('Publisher bound to port 3000');\n\nsetInterval(function() {\n  console.log('sending a multipart message envelope');\n  sock.send(['kitty cats', 'meow!']);\n}, 500);\n```\n\n**Subscriber: subber.js**\n\n```js\n// subber.js\nconst zmq = require('jszmq'); // OR import * as zmq form 'jszmq'\nconst sock = zmq.socket('sub'); // OR const sock = new zmq.Sub();\n\nsock.connect('tcp://127.0.0.1:3000');\nsock.subscribe('kitty cats');\nconsole.log('Subscriber connected to port 3000');\n\nsock.on('message', function(topic, message) {\n  console.log('received a message related to:', topic.toString(), 'containing message:', message.toString());\n});\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeromq%2Fjszmq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeromq%2Fjszmq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeromq%2Fjszmq/lists"}