# beanify

> micro-services nats nats-micro-services

Latest version **3.0.34** (published 2021-11-08) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install beanify
pnpm add beanify
yarn add beanify
bun add beanify
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.34 |
| Published | 2021-11-08 |
| First published | 2019-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10.16.0 |
| Dependencies | 13 |
| Unpacked size | 105.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | beanjs |
| Maintainers | beanjs |

## Links

- npm: https://www.npmjs.com/package/beanify
- Repository: https://github.com/beanify/beanify
- Homepage: https://github.com/beanify/beanify#readme
- Issues: https://github.com/beanify/beanify/issues
- npm.io page: https://npm.io/package/beanify

## Dependencies (13)

- [ajv](https://npm.io/package/ajv.md) ^7.1.1
- [nats](https://npm.io/package/nats.md) ^1.3.2
- [pino](https://npm.io/package/pino.md) ^5.13.5
- [async](https://npm.io/package/async.md) ^3.2.0
- [avvio](https://npm.io/package/avvio.md) ^6.2.2
- [clone](https://npm.io/package/clone.md) ^2.1.2
- [errio](https://npm.io/package/errio.md) ^1.2.2
- [fastq](https://npm.io/package/fastq.md) ^1.6.0
- [merge](https://npm.io/package/merge.md) ^2.1.0
- [semver](https://npm.io/package/semver.md) ^7.3.4
- [env-schema](https://npm.io/package/env-schema.md) ^1.1.0
- [super-error](https://npm.io/package/super-error.md) ^2.4.0
- [extra-function](https://npm.io/package/extra-function.md) ^0.0.50

## Recent versions

- 3.0.34 (latest) — 2021-11-08
- 3.0.33 — 2021-10-26
- 3.0.32 — 2021-10-18
- 3.0.31 — 2021-10-14
- 3.0.30 — 2021-09-28
- 3.0.29 — 2021-09-28
- 3.0.28 — 2021-09-08
- 3.0.27 — 2021-09-07
- 3.0.26 — 2021-08-28
- 3.0.25 — 2021-08-28
- 3.0.24 — 2021-08-28
- 3.0.23 — 2021-08-14
- 3.0.22 — 2021-08-13
- 3.0.21 — 2021-08-13
- 3.0.20 — 2021-08-03
- … 60 more at https://npm.io/package/beanify/versions

## README

<div align="center">
<img src="./imgs/beanify.png" alt="Beanify" style="width:32px">
<h1>Beanify</h1>
</div>

<p align="center">
A <a href="http://nodejs.org/">Node.js</a> microservices toolkit for the <a href="https://nats.io">NATS messaging system</a>
</p>

Beanify's inspiration came from working with [Hemera](https://github.com/hemerajs/hemera). After 3 versions of iteration, it has become a low-cost, high load capacity microservice framework. With beanify, you can start any number of services on different hosts to ensure maximum availability.

## Requirements

Node.js v10 LTS (10.16.0) or later.

## Features

- **Lightweight**: The Beanify is small as possible and provide an extensive plugin system.
- **Location transparency**: A service may be instantiated in different locations at different times. An application interacting with an service and does not know the service physical location.
- **Service Discovery**: You don't need a service discovery all subscriptions are managed by NATS.
- **Load Balancing**: Requests are load balanced (random) by NATS mechanism of "queue groups".
- **High performant**: NATS is able to handle million of requests per second.
- **Scalability**: Filtering on the subject name enables services to divide work (perhaps with locality).
- **Fault tolerance**: Auto-heals when new services are added. Configure cluster mode to be more reliable.
- **Extendible**: Beanify is fully extensible via its hooks, plugins and decorators.
- **Developer friendly**: the framework is built to be very expressive and help the developer in their daily use, without sacrificing performance and security.
- **Request & Reply**: By default point-to-point involves the fastest or first to respond.
- **Publish & Subscribe**: Beanify supports all features of NATS. This includes wildcards in subjects and normal publish and queue mechanism.

## Environment

- BEANIFY_NATS_URL: will be mapped to the `nats.url`
- BEANIFY_NATS_SERVERS: will be mapped to the `nats.servers`
- BEANIFY_NATS_USER: will be mapped to the `nats.user`
- BEANIFY_NATS_PASS: will be mapped to the `nats.pass`
- BEANIFY_NATS_TOKEN: will be mapped to the `nats.token`
- BEANIFY_PINO_LEVEL: will be mapped to the `pino.level`
- BEANIFY_PINO_PRETTY: will be mapped to the `pino.printPretty`
- BEANIFY_ROUTER_PREFIX: will be mapped to the `router.prefix`

## Install

If installing in an existing project, then Beanify can be installed into the project as a dependency:

Install with npm:

```bash
npm i beanify --save
```

Install with yarn:

```bash
yarn add beanify
```

## Example

```javascript
const beanify = require('beanify')({
  // nats:{}
  // pino:{}
  // errio:{}
  // router:{}
})

beanify
  .route({
    url: 'math.add',
    handler (req, rep) {
      const { a, b } = req.body
      rep.send(a + b)
    }
  })
  .route({
    url: 'math.sub',
    handler (req, rep) {
      const { a, b } = req.body
      rep.send(a - b)
    }
  })
  .ready(() => {
    beanify.inject({
      url: 'math.add',
      body: {
        a: 1,
        b: 2
      },
      handler (e, sum) {
        console.log(e, sum)
      }
    })
  })
```

with async-await:

```javascript
const beanify = require('beanify')({
  // nats:{}
  // pino:{}
  // errio:{}
  // router:{}
})

beanify
  .route({
    url: 'math.add',
    async handler (req) {
      const { a, b } = req.body
      return a + b
    }
  })
  .route({
    url: 'math.sub',
    async handler (req) {
      const { a, b } = req.body
      return a - b
    }
  })
  .ready(async () => {
    const sum = await beanify.inject({
      url: 'math.add',
      body: {
        a: 1,
        b: 2
      }
    })
    console.log({ sum })
  })
```

## Documentation

- [Getting Started](./docs/Getting-Started.md)
- [Encapsulation](./docs/Encapsulation.md)
- [Decorators](./docs/Decorators.md)
- [Plugins](./docs/Plugins.md)
- [Hooks](./docs/Hooks.md)
- [Route](./docs/Route.md)
- [Inject](./docs/Inject.md)
- [Request](./docs/Request.md)
- [Reply](./docs/Reply.md)
- [Beanify](./docs/Beanify.md)

<!-- - [Request and Reply](./docs/request-and-reply.md)
- [Publish and Subscribe](./docs/publish-and-subscribe.md) -->

## Ecosystem

- [beanify-cli](https://github.com/beanify/beanify-cli)
- [beanify-plugin](https://github.com/beanify/beanify-plugin)
- [beanify-autoload](https://github.com/beanify/beanify-autoload)
- [beanify-env](https://github.com/beanify/beanify-env)
- [beanify-ajv](https://github.com/beanify/beanify-ajv)
- [beanify-markdown](https://github.com/beanify/beanify-markdown)
- [smallify-beanify](https://github.com/smallify/smallify-beanify)

<!-- * [beanify-cli](https://github.com/beanjs-framework/beanify-cli)
* [beanify-env](https://github.com/beanjs-framework/beanify-env)
* [beanify-url](https://github.com/beanjs-framework/beanify-url)
* [beanify-autoload](https://github.com/beanjs-framework/beanify-autoload) -->

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