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

zerorest

v0.11.2

Published

Build microservices with ZeroMQ.

Downloads

65

Readme

ZeroREST

Build microservices with ZeroMQ.

Provides familiar express-style API as an abstraction of 0mq request-reply sockets for building REST-like microservices.

Installation

You will need ZeroMQ installed: Get ZeroMQ

npm install zerorest

Benchmarks

ZeroREST

  • 50k concurrent requests
  • 3859.51 requests/sec
  • 0.2591 ms/request

Raw Node.js HTTP

  • 10k concurrent requests
  • 1247.66 requests/sec
  • 0.8015 ms/request

See for yourself...

In the repo, you will find some convenient shell scripts for running benchmarks on your local machine.

Setup

git clone [email protected]:chuej/zerorest
cd zerorest

ZeroREST

./bin/benchmark-zerorest

OR

docker-compose run --rm service ./bin/benchmark-zerorest

HTTP

./bin/benchmark-http

OR

docker-compose run --rm service ./bin/benchmark-http

Quickstart

Service:

var ZR;

ZR = require('zerorest');

var users, zms;
zms = new ZR("tcp://0.0.0.0:5555");

users = zms.router("/users");
users.route("/findById", function(req, res, next) {
  return res.json({
    user: {
      id: req.params.id
    }
  });
});
zms.start()

Client:

var Client, client;

Client = require('zerorest').Client;

client = new Client("tcp://0.0.0.0:5555");

client.on('start', function() {
  var opts;

  opts = {
    params: {
      id: '4321'
    }
  };
  client.request('/users/findById', opts, function(err, resp) {
    return console.log(resp);
  });
});

Examples

Examples are located in the github repo:

git clone git://github.com/chuej/zerorest.git
cd zerorest
npm install

Docker / Docker Compose

The following command will start the example service, then the client.

docker-compose up

sh scripts

Service:

./bin/example-service

Client:

./bin/example-client

Usage

var ZR, startService;

ZR = require('zerorest');

startService = function() {
  var templates, users, zms;
  conf = {
    broker: {
      concurrency: 5,  // number of concurrent router sockets
      hearbeat: 2500,
      lbmode: 'rr' // load-balance mode: round-robin (rr) or random (rand)
    },
    worker: {
      concurrency: 5, // number of concurrent dealer sockets per route
      reconnect: 1000,
      heartbeat: 2500
    },
    noFork: false, // by default, zerorest will fork processes for brokers/workers
    url: "tcp://0.0.0.0:5555"
  };
  zms = new ZR("tcp://0.0.0.0:5555");
  // or
  zms = new ZR(conf);


  zms.use(function(req, res, next) {
    // middleware
    return next(null);
  });

  // array of middleware
  zms.use([function(req,res,next){ return next(null); }]);

  conf = {
    reconnect: 1000,
    heartbeat: 2500,
    path: "/users"
  };

  users = zms.router("/users");
  // or
  users = zms.router(conf);

  users.use(function(req, res, next) {
    // users specific middleware
    return next(null);
  });
  users.use(function(err, req, res, next) {
    // users specific error handler
    // calling next w/ error will continue on to service error handlers
    return next(err);
  });
  users.route("/findById", function(req, res, next) {
    return res.json({
      user: {
        id: req.params.id
      }
    });
  });
  users.route("/update", function(req, res, next) {
    res.setStatus(201);
    return res.json({
      user: {
        id: req.params.id
        link: {
          path: '/findById'
          params: {
            id: req.params.id
          }
        }
      }
    });
  });


  templates = zms.router("/templates");
  templates.route("/html", function(req, res, next) {
    return res.send("<html></html>");
  });


  zms.use(function(err, req, res, next) {
    // handler for errs generated in service
     //calling next w/ err will trigger default res.error
    return res.send("ERROR");
  });
  zms.on('error', function(err) {
    // handle uncaught service/router errors
  });
  return zms.start();
};

startService();
var Client, client;

Client = require('zerorest').Client;

client = new Client("tcp://0.0.0.0:5555");

client.on('start', function() {
  var opts, resp, stream;

  opts = {
    params: {
      id: '1234'
    },
    body: {
      data: {
        hello: "world"
      }
    },
    headers: {
      method: 'PATCH'
    },
    copts: {
      timeout: 100000
    }
  };
  client.request('/users/update', opts, function(err, resp) {
    // resp is json
    return console.log(resp);
  });


  opts = {
    params: {
      id: '4321'
    }
  };
  client.request('/templates/html', opts, function(err, resp) {
    // resp is text
    return console.log(resp);
  });


  resp = '';
  stream = client.request('/users/findById', opts);
  stream.on('data', function(data) {
    return resp += data;
  });
  return stream.on('end', function() {
    // resp is stringified json
    return console.log(resp);
  });
});

Tests

Running the test suite is as simple as cloning the repo and running npm test.

git clone git://github.com/chuej/zerorest.git
cd zerorest
npm install
npm test

Resources