I would like to announce that as the outcome of a half year’s hard work I created a brand-new microservices framework for Node.js.

What is Moleculer?

Moleculer is an open-source fast & flexible microservices framework, licensed under MIT. It contains most of all important microservices features (service registry, auto-discovery, load balancing, circuit-breaker, bulkhead, fallback response…etc).

Key features

Promise-based solution

request-reply concept

supports the event-driven architecture with balancing

supports middlewares

built-in caching solution (Memory, Redis)

pluggable transporters (TCP, NATS, MQTT, Redis, AMQP, NATS Streaming, Kafka)

pluggable serializers (JSON, Avro, MsgPack, Protocol Buffer, Thrift)

load-balanced requests (round-robin, random)

auto-discovery services & built-in service registry

master-less architecture, all nodes are equal

built-in metrics feature with reporters (Console, CSV, Datadog, Event, Prometheus, StatsD)

built-in tracing feature with exporters (Console, Datadog, Event, Jaeger, Zipkin)

Install

Moleculer is available as an npm package. You can install it with npm or yarn

$ npm i moleculer

Usage

This simple example shows you how easy to create a service in Moleculer and call it.

As you can see above, we created a math service which has an add action. This action is able to add two numbers, the values of “a” and “b” parameters. After it created, we can call it with the broker.call method. The first parameter is the calling path (service name + action name), the second parameter is the “params” which is passed to the action handler wrapped to a Context object.

You can try it in your browser on CodeSandbox!

Create a microservices project

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

Install moleculer-cli globally

npm install moleculer-cli -g

2. Create a new project (named moleculer-demo )

moleculer init project moleculer-demo

Press “Enter” on all questions to use default options.

This starter project template creates two sample services (greeter, products) with Jest tests and an API Gateway.

3. Open the project folder and start it

cd moleculer-demo

npm run dev

4. Open the http://localhost:3000/ link in your browser. On the Welcome page, you can call the services via the API gateway.

Congratulations! You have just created your first Moleculer-based microservices project. Welcome to the microservices world!