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

socket.io-reqev

v0.2.5

Published

A framework for [socket.io](http://socket.io/) (server and client).

Readme

socket.io-reqev

A framework for socket.io (server and client). this version corresponds to socket.io >= ver 1.0 if you want to use socket.io ver 0.9.x, choose socket.io-reqev ver 0.1.4

It is designed to make pub-sub and GET request easier. It allows you to write less code and easy to understand.

socket.io-reqev ties a path to an object and ties an event to a room.

Install

npm install socket.io-reqev

How to use

server(node.js)

var events = require('events');

var Sample = function(time){
  setInterval(function(){this.emit("alarm", {time: new Date().toString()})}.bind(this),time);
  this.events = ["alarm"];
}
Sample.prototype = new events.EventEmitter();
Sample.prototype.request = function(req,cb){ return req == "now" ?  cb(null,new Date().toString()) : cb("invalid")}

var IOReqEv = require('socket.io-reqev');
var ioReqEv = new IOReqEv(require('socket.io').listen(50000));

ioReqEv.register("/sample",new Sample(1000));
ioReqEv.register("/sample1",new Sample(10000));

client(browser)

//<script src="http://cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js"></script>
//<script src="https://raw.github.com/takeshy/socket.io-reqev/master/dist/io-reqev-client.js"></script>
sock = new IOReqEvClient("http://localhost:50000/sample", function(obj){console.log(obj)})
sock.watch({requests: ["now"],events: ["alarm"]})
// when no need to use.
// sock.unwatch() 

API

Node.js

IOReqEv

Create a new IOReqEv with Socket.IO object.

var IOReqEv = require('socket.io-reqev')`
var ioReqEv = new IOReqEv(require('socket.io').listen(50000));

register(path:string,service:object)

  • path is tied path of socket.io url(SocketIO Host Name + /path)

  • service consists two parts.

    • events

      (optional) it is array and including event names. if the object emits an event included this field,socket.io-reqev sends to the subscribers that event.

    • request

      (optional)it is method function(reqest,callback). param request is a request of requests from a client. param callback is a function(error,value). when this method completes the request, this method shuold call the callback with the value and socket.io-recv replies the value to the client.

var events = require('events');

var Sample = function(time){
  setInterval(function(){this.emit("alarm", {time: new Date().toString()})}.bind(this),time);
  this.events = ["alarm"];
}
Sample.prototype = new events.EventEmitter();
Sample.prototype.request = function(req,cb){ return req == "now" ?  cb(null,new Date().toString()) : cb("invalid")}
ioReqEv.register("/sample",new Sample(1000));

Browser

IOReqEvClient(url:string,callback:function,errorCallback:function)

  • url socket.io host + path
  • callback it is called when socket.io host replies successful.
  • errorCallback it is called when socket.io host replies unsuccessful.

watch(requests:array,events:array)

you call this method whenever you want.

  • requests(optional)

An array of request. Each request passes server side object's method named 'request'. it is similar to HTTP GET but you can include multiple requests at once.

  • events(optional)

An array of event name you want to subscribe. if you called watch already,socket-io-recv unsubscribes befores events. For that reason,if you want to keep subscribe,you should include all events you want subscribe or if events is not passed or null,socket-io-recv subscribing befores events. if you don't subscribe any event anymore,you should set empty array.

sock = new IOReqEvClient("http://localhost:50000/sample", function(obj){console.log(obj)})
sock.watch({requests: ["now"],events: ["alarm"]})

unwatch()

you don't need any request and event,then you call this method.

var socket.unwatch();

demo

if you don't understand, you can use demo and view demo/app.js and demo/index.html.

git clone https://github.com/takeshy/socket.io-reqev.git
cd socket.io-reqev/demo
npm install
node app.js
  • browser

    http://localhost:8080

License

MIT