# @sensorfactdev/mock-node-nats

> A mock NATS client for Node.js

Latest version **0.3.3** (published 2021-12-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sensorfactdev/mock-node-nats
pnpm add @sensorfactdev/mock-node-nats
yarn add @sensorfactdev/mock-node-nats
bun add @sensorfactdev/mock-node-nats
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.3 |
| Published | 2021-12-10 |
| First published | 2018-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Alexandre Borrego |
| Maintainers | millitza, karimcitoh, bouke.krom, zoiderberg_nl, davydkov, jamessensorfact |

## Links

- npm: https://www.npmjs.com/package/@sensorfactdev/mock-node-nats
- Repository: https://github.com/Sensorfactdev/mock-node-nats
- npm.io page: https://npm.io/package/@sensorfactdev/mock-node-nats

## Dependencies (1)

- [uuid](https://npm.io/package/uuid.md) ^3.2.1

## Recent versions

- 0.3.3 (latest) — 2021-12-10
- 0.3.2 — 2019-07-08
- 0.3.1 — 2018-07-20
- 0.3.0 — 2018-07-17
- 0.2.0 — 2018-07-09
- 0.1.1 — 2018-05-23
- 0.1.0 — 2018-05-23

## README

# `mock-node-nats`

This is a small mocking library aimed at facilitating tests of our NATS-connected services.

It exposes a `NATS` class based on the API provided by [`node-nats`](https://github.com/nats-io/node-nats). It maintains an in-memory "bus" shared accross the class' instances.

**NB**: This is very much a work in progress that fits our particular current needs. Additional development is needed to mock the `node-nats` API more faithfully, e.g. supporting options, completing the signatures of existing methods, etc.


## Installation

```
npm install @sensorfactdev/mock-node-nats
```

## Usage

```js
const NATS = require(@sensorfactdev/mock-node-nats);
const nats = NATS.connect();

// Simple Publisher
nats.publish('subject', 'message!');

// Simple Subscriber
nats.subscribe('subject', msg => {
  console.log(`Received a message: ${msg}`);
});

// Unsubscribing
const sid = nats.subscribe('subject', msg => {});
nats.unsubscribe(sid);

// Request
const sid = nats.request('request', res => {
  console.log(`Received a message: ${res}`););
});

// Access the list of subs (useful for testing)
const subs = nats.subs;

// Close connection
nats.close();

```

---
_Source: https://npm.io/package/@sensorfactdev/mock-node-nats · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
