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 🙏

© 2021 – Pkg Stats / Ryan Hefner

fastify-nats-client

v2.2.0

Published

Fastify plugin for using NATS

Downloads

42

Readme

fastify-nats-client

NPM Version NPM Downloads Code Style Coverage Status dependencies Status devDependencies Status

Fastify Plugin to use NATS Server as a queue, to exchange messages.

Under the hood Node NATS client is used, the options that you pass to register will be passed to the nats client.

Usage

Add it to you project with register and you are done!
You can access the nats Connection via fastify.nats.

const fastify = require('fastify')

// register the plugin with some options, for example:
fastify.register(require('fastify-nats-client'), {
  url: 'nats://demo.nats.io:4222'
}, err => {
  if (err) throw err
})

fastify.listen(3000, (err, address) => {
  if (err) throw err
  console.log(`server listening on ${address}`)
})

and later

fastify.nats.publish(topic, message);

Requirements

Fastify ^2.15.3 , Node.js 8.17.x (but recommended 10.23.1) or later. Note that plugin releases 2.x are for Fastify 2.x, etc.

Sources

Source code is all inside main repo: fastify-nats-client.

Documentation generated from source code (library API): here.

Note

All the code here is based on the work done initially by its original author (mahmed8003 [email protected]), in the upstream repository fastify-nats, under the MIT license.

The plugin decorate Fastify and expose some functions:

  • nats, the NATS Connection to use

Some plugin options are forwarder to Node NATS client, like:

  • url, the absolute URL of the NATS Server to use (including the port) while others are only used inside the plugin, to configure its behavior, like:
  • disableDefaultNATSServer, flag (by default false) to disable connections to default NATS Server (so if url is not specified, an Error will be raised); could be useful to avoid connections to that (external and public) server, for example by plugin configuration mistake

all plugin options are optional, and have a default value set in the plugin.

Default url for NATS Server in the plugin is set to nats://demo.nats.io:4222, to be able to do a quick start; anyway note that in some cases it could not be reachable (for example by corporate firewall rules), so even plugin tests could fail in that case. To perform some local tests, it's possible to use a NATS Server Docker image from standard image NATS - DockerHub; for convenience, they are defined in package.json like docker:nats:start and the same for log|process|stop etc.

License

Licensed under MIT.