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 🙏

© 2024 – Pkg Stats / Ryan Hefner

talk

v0.7.1

Published

Abstract the way your node appications talk to each other so you can implement what ever protocol you want (http, sockets etc) with the same interface

Downloads

168

Readme

talk

Talk is a node module to help you abtract the way your node applications talk to each. You dont need to decide if you want to use http/REST or sockets or websockets or something else from day one. Often, when creating a complex server/service setup, you might now know exatcly how the end result will be. Optimizing a solution is therefore quite hard. So if you choose the way your services talk to eachother too early, you might need to change quite a lot at the end.

Talk gives you an easy interface to both setup and communicate with your services. It is up to you later so change, add or optimize the protocol it uses.

Basics

At its heart, it exposes two communication patterns:

  • Request / Response
  • Publisher / Subscriber

That means that you can create a server and talk to it and use either protocol without it affecting how you write your application.

Simple req/res example:

We create a server:

var server = talk.reqrep.serve({port: 11177, protocol: 'http'});

server.on('hej', function(payload, meta) {
    return Promise.resolve({thanks: true});
});

server.start()
    .then(function() {
        console.log('The server is listening');
    });

And a client:

var client = talk.reqrep.client({ protocol: 'http' });

client.send('localhost:11177', 'hej', {foo: 'bar'})
    .then(function(result) {
        console.log('Got this from the server: ', result);
    });

... and the same with socketio

We create a server (the only difference being that we change it to socketio):

var server = talk.reqrep.serve({port: 11177, protocol: 'socketio'});

server.on('hej', function(payload, meta) {
    return Promise.resolve({thanks: true});
});

server.start()
    .then(function() {
        console.log('The server is listening');
    });

And a client:

var client = talk.reqrep.client({ protocol: 'socketio' });

client.send('localhost:11177', 'hej', {foo: 'bar'})
    .then(function(result) {
        console.log('Got this from the server: ', result);
    });

Gzipping your data (currently only works with socketio)

Server:

// just add the gzip flag and all content sent back to the client will be gzipped
var server = talk.reqrep.serve({port: 11177, protocol: 'socketio', gzip: true});

server.on('hej', function(payload, meta) {
    return Promise.resolve({thanks: true});
});

server.start()
    .then(function() {
        console.log('The server is listening');
    });

And a client:

// Add the gzip flag and all content sent to the server will be gzipped
var client = talk.reqrep.client({ protocol: 'socketio', gzip: true });

client.send('localhost:11177', 'hej', {foo: 'bar'})
    .then(function(result) {
        console.log('Got this from the server: ', result);
    });

client.send('localhost:11177', 'hej', {foo: 'bar'})
    .then(function(result) {
        console.log('Got this from the server: ', result);
    });

Sending binary data

var buffer = .... // your cool buffer
client.send('localhost:11177', 'hej', buffer, { binary: true })
    .then(function(result) {
        console.log('Got this from the server: ', result);
    });

Simple pub/sub (with socketio and redis)

The pubsub uses socketio through a redis adapter so your events are mited to all your subscribing clients.

The subscriber:

var pubsub = talk.pubsub({ host: '127.0.0.1', port: 6379 });

pubsub.on('hej', function(payload) {
    console.log(payload);
});

The publisher:

var pubsub = talk.pubsub({ host: '127.0.0.1', port: 6379 });
pubsub.emit('hej', {foo: 'bar'});

Next steps

  • ~~Add pub/sub (yeah I know, it should be there)~~ Done!
  • Add signing of payload (jwt)
  • Add methods to add balancing functions from outside the module
  • Add methods to add protocols from outside the module
  • Make it more pluggable so its easier to add more protocols

Contributions

The idea to do this came from when Camilo Tapia and Chris Hedgate discussed how to create an application for a client.