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

spawnpoint-nats

v2.2.0

Published

NATS Plugin for Spawnpoint on NPM

Downloads

127

Readme

spawnpoint-nats.js

NATS Plugin for Spawnpoint on NPM

npm version dependencies Status Actions Status Greenkeeper badge

Installation

Make sure to install NATS and the plugin for Spawnpoint NATS separately. NATS is treated as a peer dependency so you can change version separately. npm i nats spawnpoint-nats

NATS Versions

  • This module's version 2.x.x is designed for a NATS server running 2.x
  • This module's version 1.x.x is designed for a NATS server running 1.x

API

This api is mounted at app.nats to access these methods:

app.nats.publish(subject, message, callback)

Sends a message to a subscriber. Expects no response. Callback issued when message is sent to the NATS server. No guarantee of receipt.

  • subject string - subject to publish message to
  • message object|array|string|buffer - Message body for published message
  • callback function - Optional callback fired when sent
app.nats.request(subject, message, options, callback, updateCallback)

Sends a message to a subscriber with the expectation of at least one reply. Main callback only listens for the final reply. Can get updates to provide realtime stats/progress and/or acknowledgments to reset timeouts. Returns event emitter for update, ack, response, & timeout events.

  • subject string - subject to publish message to
  • message object|array|string|buffer - Message body for published message
  • options object - Options passed to PUB method.
    • max number - Number of replies to receive before unsubscribing from replies, optional
    • timeout number - Number of ms to wait until firing a timeout error. If omitted it will default to config settings. Setting to falsey value will disable timeout
  • callback function - Optional callback fired when final response is sent. Callback includes two arguments
    • err error|null - If the response failed via timeout or was reported as an error from the response.
    • results *object|array|string|buffer - Response body
  • updateCallback function - Optional callback fired when update is sent. Callback includes one argument
    • results object|array|string|buffer - Response body
Example:
app.nats.request('lookup', {
   domain: "google.com"
 }, function(err, results){
     if(err){
       return console.error('ERROR', err);
     }
     console.log('Lookup results', results);
 }, function(update){
   console.log('update', update);
 });
app.nats.subscribe(subject, options, callback, updateCallback)

Sends a message to a subscriber with the expectation of at least one reply. Main callback only listens for the final reply. Can get updates to provide realtime stats/progress and/or acknowledgments to reset timeouts. Returns event emitter for update, ack, response, & timeout events.

  • subject string - subject to subscribe to
  • options object - Options passed to PUB method.
    • queue string - Name of queue to join
    • max number - Maximum number of messages to receive before automatically unsubscribing.
    • noAck boolean - Prevents automatic ack message when set to true. Defaults to false.
    • noPrefix string - Prevents configurable prefix string from adding to subject. Defaults to false.
  • callback function - callback fired when messages are received. Callback includes two arguments
    • response object|array|string|buffer - Message body
    • handler eventEmitter - Event emitter with helper methods to handle updates, acks, and replies.
      • Emittable EVENTS - These events need to be emitted to send messages
        • ack - timeout int: Resets the timeout for the request. If not timeout is specified it will reset the timer that was used by the requester. timeout is in ms.
        • update - data string: Sends a message with data update the request. Also resets the timeout.
        • response - err error|null, results object|array|string|buffer: Sends an error or response to the request
      • Helper Methods - These methods are helper methods to make emitting the events above easier
        • ack(): Tells the request to reset timeout, has no body or data to send
        • update(data *string*): Sends a message with data update the request. Also resets the timeout.
        • response(err *error|null*, results *object|array|string|buffer*): Sends an error or response to the request
    • subject string - Copy of the message subject. Useful for wildcard subscriptions. Does not include prefix where applicable.
Example:
app.nats.handle('lookup', {
   queue: "dns.lookup"
 }, function(msg, handler){
   setTimeout(function(){
     handler.ack();
   }, 2500);
   setTimeout(function(){
     handler.update({
       pending: true
     });
   }, 5000);
   setTimeout(function(){
     handler.response(null, msg);
   }, 7500);
 });