Moleculer

Progressive microservices framework for Node.js

README

Moleculer logo

CI test Coverage Status Maintainability Codacy Badge Known Vulnerabilities Discord chat
Downloads FOSSA Status [Patreon][patreon]

Moleculer NPM version Twitter URL



Moleculer is a fast, modern and powerful microservices framework for Node.js. It helps you to build efficient, reliable & scalable services. Moleculer provides many features for building and managing your microservices.
<!--
undefined
undefined
undefined
undefined
-->



Top sponsors




What's included


- Promise-based solution (async/await compatible)
- request-reply concept
- support event driven architecture with balancing
- built-in service registry & dynamic service discovery
- load balanced requests & events (round-robin, random, cpu-usage, latency, sharding)
- many fault tolerance features (Circuit Breaker, Bulkhead, Retry, Timeout, Fallback)
- plugin/middleware system
- support versioned services
- support Streams
- service mixins
- built-in caching solution (Memory, MemoryLRU, Redis)
- pluggable loggers (Console, File, Pino, Bunyan, Winston, Debug, Datadog, Log4js)
- pluggable transporters (TCP, NATS, MQTT, Redis, NATS Streaming, Kafka, AMQP 0.9, AMQP 1.0)
- pluggable serializers (JSON, Avro, MsgPack, Protocol Buffer, Thrift, CBOR, Notepack)
- pluggable parameter validator
- multiple services on a node/server
- master-less architecture, all nodes are equal
- built-in parameter validation with fastest-validator
- built-in metrics feature with reporters (Console, CSV, Datadog, Event, Prometheus, StatsD)
- built-in tracing feature with exporters (Console, Datadog, Event, Jaeger, Zipkin, NewRelic)
- official API gateway, Database access and many other modules...

Installation

  1. ```
  2. $ npm i moleculer
  3. ```
or
  1. ```
  2. $ yarn add moleculer
  3. ```

Create your first microservice

This example shows you how to create a small service with an add action which can add two numbers and how to call it.
  1. ``` js
  2. const { ServiceBroker } = require("moleculer");

  3. // Create a broker
  4. const broker = new ServiceBroker();

  5. // Create a service
  6. broker.createService({
  7.     name: "math",
  8.     actions: {
  9.         add(ctx) {
  10.             return Number(ctx.params.a) + Number(ctx.params.b);
  11.         }
  12.     }
  13. });

  14. // Start broker
  15. broker.start()
  16.     // Call service
  17.     .then(() => broker.call("math.add", { a: 5, b: 3 }))
  18.     .then(res => console.log("5 + 3 =", res))
  19.     .catch(err => console.error(`Error occurred! ${err.message}`));
  20. ```

Create a Moleculer project

Use the Moleculer CLI tool to create a new Moleculer based microservices project.

1. Create a new project (named moleculer-demo)
  1. ``` sh
  2.     $ npx moleculer-cli -c moleculer init project moleculer-demo
  3. ```
    
2. Open the project folder
  1. ``` sh
  2.     $ cd moleculer-demo
  3. ```
    
3. Start the project
  1. ``` sh
  2.     $ npm run dev
  3. ```

4. Open the http://localhost:3000/ link in your browser. It shows a welcome page that contains more information about your project & you can test the generated services.

:tada: Congratulations! Your first Moleculer-based microservices project is created. Read our documentation to learn more about Moleculer.

Welcome page

Official modules

We have many official modules for Moleculer. Check our list!

Supporting

Moleculer is an open source project. It is free to use for your personal or commercial projects. However, developing it takes up all our free time to make it better and better on a daily basis. If you like Moleculer framework, please support it.

Thank you very much!

For enterprise


Available as part of the Tidelift Subscription.

The maintainers of moleculer and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Documentation

You can find here the documentation.

Changelog


Security contact information

To report a security vulnerability, please use the Tidelift security contact.
Tidelift will coordinate the fix and disclosure.

Contributions

We welcome you to join in the development of Moleculer. Please read our contribution guide.

Project activity


Alt

License

Moleculer is available under the MIT license.


Contact

Copyright (c) 2016-2022 MoleculerJS
@moleculerjs @MoleculerJS

[patreon]: https://www.patreon.com/bePatron?u=6245171