fastify-nats-ts
v0.1.9
Published
Modern plugin for using a NATS client within Fastify
Downloads
28
Readme
NATS for Fastify
Modern plugin for using a NATS client within Fastify
This plugin is based upon the nats.js library and fully supports TypeScript. It's a partial and safe rewrite of the legacy fastify-nats-client plugin and aims to supersede it.
Usage
To install this plugin, simply install it via your package manager:
npm i fastify-nats-tsYou can then start using it inside of your app:
import Fastify from "fastify";
import fastifyNats from "fastify-nats-ts";
const fastify = Fastify();
await fastify.register(fastifyNats, { servers: "nats.example.com:4222" });
// Publish a message using the client
fastify.nc.publish("subject", "message");
// Get the library itself if required
console.log(fastify.nats);Options
You can directly pipe any nats.js options straight into the plugin at register-time like so:
await fastify.register(fastifyNats, {
servers: ["coolserver.net:4222", "backup.com:4222"],
maxPingOut: 5,
pass: "password123"
});The plugin also includes the defaultServer and drainOnClose booleans, enabling you to fallback to the NATS demo server and drain instead of flushing on exit respectively.
