Gathering detailed insights and metrics for 1
Gathering detailed insights and metrics for 1
Gathering detailed insights and metrics for 1
Gathering detailed insights and metrics for 1
npm install 1
Typescript
Module System
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
13 Stars
48 Commits
4 Forks
2 Watchers
2 Branches
7 Contributors
Updated on Apr 10, 2023
Latest Version
0.1.2
Package Id
1@0.1.2
Size
6.78 kB
NPM Version
1.4.6
Published on
Apr 08, 2014
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Distributed pub/sub based in ØMQ.
1 (pronounced One) is a sort of magnet module, gluing together all the nodes that you launch in a network, and providing a simple pub/sub. It allows you to separate several services in the same network by means of
Before you install the module through NPM, using npm install 1
, make sure you
take care of the instructions below.
The first thing to do, is to install ØMQ. Head to http://www.zeromq.org/intro:get-the-software and follow the instructions for your operating system. Then, use the instructions below, once again, depending on your operating system.
Also, you might want to tune your OS in order to solve some known issues with default configurations. To do this, head out to http://www.zeromq.org/docs:tuning-zeromq, and follow the instructions.
Note: If you are installing on a system that is not covered by these instructions, and manage to install, please share your instructions, so we can improve the documentation.
Installing on debian-like operating systems, requires that you run the following:
# apt-get install libavahi-compat-libdnssd-dev libc-ares2 libzmq-dev
You will need XCode command line tools to install One on MacOS X, since it depends on mdns and zmq.
1var One = require('1'); 2 3var one = new One(); 4 5// Let's do something when we receive messages. 6one.on('message', function (chan, msg) { 7 console.info(chan + '>', msg); 8}); 9 10// Join the cluster. 11one.join(function (err, cluster) { 12 err && throw new Error('Unable to join cluster: ' + err); 13 14 // Advertise the service. 15 one.advertise(function (err, adInfo) { 16 err && throw new Error('Unable to advertise service: ' + err); 17 18 // Subscribe a channel 19 one.subscribe('some_channel', function (err, chan) { 20 err && throw new Error('Unable to subscribe channel: ' + err); 21 22 // Let's send a message to the channel periodically 23 setTimeout(function () { 24 one.publish('some_channel', 'You will be notified of this message'); 25 26 one.publish('some_channel_you_did_not_subscribe', 'You will not get this message'); 27 }, 500); 28 }); 29 }); 30});
Here's a more elaborate way of instantiating One, with a few extra options:
1// You can pass a few options when instantiating One.
2// Note that these are all optional, and you can instantiate without any option.
3// The example below shows all the default options.
4var one = new One({
5 // Id of the service you will be providing.
6 service: 'unnamedService',
7
8 // Cluster which this node belongs to.
9 cluster: 'defaultCluster',
10
11 // Id of this node. If null, a random id is generated.
12 id: null,
13
14 // Port used for publishing messages. If null, a free random port is used.
15 port: null,
16
17 // Interface in which the node will bind.
18 address: '0.0.0.0'
19});
This module can be used to easily create auto discoverable services that communicate through means of a distributed pub/sub. Unlike solutions based on Redis or some message queueing software, this module is based on 0MQ, enabling you to create a pub/sub without a single point of failure or bottleneck.
Upon instantiation of One, you can specify the service
which you are providing. This acts as an immediate identifier in case you create multiple service types that you don't want talking to each other. Only after you start advertising other nodes in the cluster will realise you have joined and listen to you. Until that moment, you are a silent node, which is only capable of listening.
Usage:
1var one = new One({ 2 service: 'myStorageService' 3}); 4 5// ... 6 7// Advertising service 8one.advertise(function (err, adInfo) { 9 !err && console.log('Advertising', adInfo); 10}); 11 12// ... 13 14// Stopping advertisement 15one.stopAdvertise(function (err, adInfo) { 16 !err && console.log('Stopped advertising', adInfo); 17}); 18
Unlike service
, clustering allows you to partition multiple nodes of the same service in the same network. Basically, only nodes belonging to the same cluster
will talk to each other.
Usage:
1var one = new One({ 2 service: 'myStorageService', 3 cluster: 'cluster1' 4}); 5 6// Joining cluster 7one.join(function (err, cluster) { 8 !err && console.log('Joined', cluster); 9}); 10 11// ... 12 13// Leaving cluster 14one.leave(function (err, cluster) { 15 !err && console.log('Left', cluster); 16});
Here's a complete list of the available events that you can listen to:
1one.on('join', function (cluster) { 2 console.log('joined cluster:', cluster); 3}); 4 5one.on('leave', function (cluster) { 6 console.log('left cluster:', cluster); 7}); 8 9one.on('advertise_start', function (adInfo) { 10 console.log('started advertising:', adInfo); 11}); 12 13one.on('advertise_stop', function (adInfo) { 14 console.log('stopped advertising:', adInfo); 15}); 16 17one.on('subscribe', function (channel) { 18 console.log('subscribed:', channel); 19}); 20 21one.on('unsubscribe', function (channel) { 22 console.log('unsubscribed:', channel); 23}); 24 25one.on('node_up', function (node) { 26 console.log('node up:', node); 27}); 28 29one.on('node_down', function (node) { 30 console.log('node down:', node); 31}); 32 33one.on('message', function (chan, payload) { 34 console.log(chan + '>', payload); 35}); 36 37// Note that the error event is only emitted if you do not specify a callback to 38// a method that throws an error. 39one.on('error', function (err) { 40 console.error('ERROR: ', err); 41});
Released under the MIT License.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 2/29 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More