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

zquest

v1.1.2

Published

Promise based request socket client

Downloads

9

Readme

zquest

Build Status

Promise based ØMQ request client.

Best used in tandem with the zeromatter server framework.

Usage

Zquest is designed to loosely follow the request module. It comes with several build in friendly features:

  • Self managing socket pool
    • Self expiring (10 min default), including member socket cleanup
    • Auto scaling of member sockets within bounds (2-500 default)
    • Socket acquisition timeouts
  • Self expiring sockets (10 min default)
  • Mapping of one socket pool per host

Example

Client

let zquest = require('zquest');

// tcp://localhost:5555
zquest({
  message: 'testing'
}).then((data) => console.log(data)) // => testing

// tcp://127.0.0.1:5555
zquest({
  host: '127.0.0.1',
  port: 5555,
  message: 'testing'
}).then((data) => console.log(data)) // => testing

Simple Server (Blocking)

NOTE for non-blocking, see the reflector server used for testing

let zmq = require('zmq');
let zquest = require('zquest');

let socket = zmq.socket('rep');
socket.bindSync(`tcp://localhost:5555`);

socket.on('message', (msg) => {
msg = zquest.parse(msg);
console.log(msg.data); // => testing
socket.send(msg._request_id + ':' + msg.data);
});

Key

Caveat

the responding server MUST return the request ID as part of the response. As either a property _request_id or prefixed to the request as [ID]:

Eg:

zquest({ data: 'testing' });

socket.on('message', (message) => {
  message = zquest.parse(message); // => { _request_id: b6c537f5-73cb-4681-9d4c-786248c4dc93, data: 'testing' }

  // Either:
  socket.send(message._request_id + ':hello_world');

  // OR
  socket.send({
    _request_id: message._request_id,
    data: 'hello_world'
  });
});

Documentation

Defaults

defaults used by all zquest clients

{
  "host": "127.0.0.1",
  "port": 5555,
  "timeout": 10000
  "pool": {
    "min": 2,
    "max": 500,
    "socket_expire": 600000,
    "self_expire": 600000,
    "acquire_retry": 100,
    "acquire_attempts": 10
  }
}

zquest(req)

  • Shared zquest client
  • Accepts
    • host - host to connect to [default: 127.0.0.1]
    • port - port to connect to [default: 5555]
    • data|message|body - message data to send
  • Returns
    • Promise
zquest({
    host: '127.0.0.1',
    port: 5555,
    message: 'testing'
}).then((response) => console.log(response))

zquest.defaults(opts)

  • Set defaults for the shared zquest client
  • Accepts
zquest.defaults({
  host: 'myserver.google.com',
  pool: {
    min: 5
  }
});

zquest.close()

  • Close and clean all pools/sockets
zquest.close();

zquest.client

  • Shared zquest client
zquest.client;
zquest.client.request() // === zquest()

zquest.new(message)

  • Utility to retrieve a new zquest client
  • Accepts
  • Returns
    • New zquest client with its own independent configuration and defaults
let myserver = zquest.new({
  host: 'myserver.google.com',
  pool: {
    min: 5
  }
});

myserver.defaults();
myserver.request();

zquest.parse(message)

  • Proxy of zquest.parse.message
  • Accepts
    • Buffer or String message
  • Returns
    • Object
      • _request_id - request ID which must be returned in the response for routing purposes
      • data - data in the message
let message = zquest.parse(message);
console.log(message); // => { _request_id: [SOME_GUID], data: [BODY] }

zquest.parse.message(message)

  • Message parser used by the zquest client
  • Accepts
    • Buffer or String message
  • Returns
    • Object
      • _request_id - request ID which must be returned in the response for routing purposes
      • data - data in the message
let message = zquest.parse.message(message);
console.log(message); // => { _request_id: [SOME_GUID], data: [BODY] }

zquest.parse.messageId(message)

  • Parser for retrieving only the message ID
  • Accepts
    • Buffer or String message
  • Returns
    • Request ID which must be returned in the response for routing purposes
let id = zquest.parse(message);
console.log(id); // => [SOME_UUID]

Authors