Registry / web-framework / moleculer

moleculer

JSON →
library0.15.0jsnpmunverified

Moleculer is a fast, modern, and powerful microservices framework for Node.js, designed to build efficient, reliable, and scalable distributed systems. It provides a comprehensive set of features including a promise-based request-reply mechanism, event-driven architecture, dynamic service discovery, load balancing, and fault tolerance capabilities like Circuit Breaker and Retry. The current stable version is 0.15.0, with frequent minor and patch releases, and major updates approximately annually, often introducing significant breaking changes. Key differentiators include its pluggable architecture for transporters (e.g., NATS, Redis, Kafka), serializers (e.g., MsgPack, CBOR), caching, loggers, and metrics/tracing reporters. It emphasizes a master-less architecture, making all nodes equal, and comes with built-in parameter validation and extensive TypeScript support.

npm install moleculer
INSTALL
IMPORT
SIG · MOLECULER
M
moleculer
web-frameworkjavascriptv0.15.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ServiceBroker
import { ServiceBroker } from 'moleculer';
const { ServiceBroker } = require('moleculer');
Moleculer v0.15 is primarily ESM-first. While CommonJS might still work in some setups, the recommended approach is ESM. `ServiceBroker` is the core class for creating and managing a broker instance.
Service
import { Service } from 'moleculer';
import Service from 'moleculer/service';
The base class for defining services. Always imported as a named export from the main 'moleculer' package. For TypeScript, it's also the base class for type inference.
ServiceSchema
import { ServiceSchema } from 'moleculer';
import { ServiceSchema } from 'moleculer/types';
The primary interface for defining service configurations and actions. It's a type, but also implicitly inferred when defining service objects.
Transporters
import { Transporters } from 'moleculer';
import { NatsTransporter } from 'moleculer/transporters/nats';
Transporters namespace provides access to various built-in transporters like `Nats`, `Redis`, `Kafka`, etc. Generally accessed as `new Transporters.Nats(...)`.

This quickstart demonstrates how to create a basic Moleculer service, define actions and events, start the service broker, and then call an action and emit an event.

import { ServiceBroker, ServiceSchema } from 'moleculer'; // Create a ServiceBroker const broker = new ServiceBroker({ nodeID: 'node-greeter-1', logLevel: 'info', transporter: 'NATS' // Or 'Redis', 'TCP', etc. }); // Define a Greeter Service const GreeterService: ServiceSchema = { name: 'greeter', settings: { defaultName: 'World' }, actions: { hello: { rest: 'GET /hello', async handler(ctx) { return `Hello ${ctx.params.name || this.settings.defaultName}`; } }, welcome: { async handler(ctx) { this.logger.info(`Welcoming ${ctx.params.name}...`); return `Welcome, ${ctx.params.name}`; } } }, events: { 'user.created': { async handler(ctx) { this.logger.info(`User created event received for ${ctx.params.username}`); } } }, async started() { this.logger.info(`Greeter service started on node ${broker.nodeID}`); }, async stopped() { this.logger.info(`Greeter service stopped on node ${broker.nodeID}`); } }; // Create a service from the schema broker.createService(GreeterService); // Start the broker broker.start() .then(async () => { // Call an action const res = await broker.call('greeter.hello', { name: 'Moleculer' }); console.log(res); // Emit an event await broker.emit('user.created', { username: 'Alice' }); // Call an action from another node if available (assuming multiple nodes) const welcomeMsg = await broker.call('greeter.welcome', { name: 'Bob' }); console.log(welcomeMsg); // Stop the broker after a delay or on signal setTimeout(() => broker.stop(), 5000); }) .catch(err => { broker.logger.error('Error starting broker:', err); });
moleculer --version
Debug
Known issues
breakingMoleculer v0.15.0 significantly increased the minimum Node.js version requirement. It now requires Node.js >= 22.x.x.
fix
Upgrade your Node.js runtime to version 22 or newer. Ensure your deployment environment meets this requirement.
affects: >=0.15.0
breakingThe Moleculer communication protocol has been changed in v0.15.0 to version 5. Nodes running v0.15.x will not be able to communicate with nodes running v0.14.x or older due to protocol incompatibility.
fix
All nodes in your Moleculer cluster must be upgraded to v0.15.0 simultaneously to maintain communication. Consider a phased rollout with caution, or a complete upgrade of the entire microservices mesh.
affects: >=0.15.0
breakingSchema-based serializers were removed from the core in v0.15.0. If you were relying on custom schema-based serializers, they need to be reimplemented or replaced with other serialization options.
fix
Review your serialization strategy. Moleculer still supports pluggable serializers like JSON, JSONExt, MsgPack, CBOR, and Notepack. Migrate to one of these or implement a custom serializer as a plugin.
affects: >=0.15.0
gotchaMoleculer relies heavily on various peer dependencies for its pluggable components (transporters, loggers, serializers, metrics, tracing). Forgetting to install the specific peer dependency for a chosen component will lead to runtime errors.
fix
Always install the required peer dependency for any specific transporter, logger, or other module you configure. For example, if using `transporter: 'NATS'`, you must `npm install nats`.
affects: >=0.10.0
gotchaWhen developing with TypeScript, ensure your `tsconfig.json` targets an ECMAScript version that supports `async/await` (e.g., `es2017` or higher) and includes `esnext.asynciterable` if using streams, and that `moduleResolution` is set to `node` or `nodenext`.
fix
Verify `"target": "es2017"` (or higher) and `"moduleResolution": "node"` or `"nodenext"` in your `tsconfig.json`. Consider adding `"lib": ["es2017", "esnext.asynciterable"]` for full type coverage.
affects: >=0.14.0
Errors
Common errors & fixes
Error: Missing transporter module.
You configured a transporter (e.g., 'NATS', 'Redis') in your `ServiceBroker` options but did not install its corresponding npm package.
fix
Install the required package. For example, if using NATS, run `npm install nats` (or `yarn add nats`).
TypeError: broker.call is not a function or broker.emit is not a function
Attempting to call actions or emit events on the `ServiceBroker` instance before it has been started or after it has been stopped.
fix
Ensure `broker.start()` has successfully resolved before making any calls or emits. Wrap your logic within the `.then()` block of `broker.start()` or ensure a running broker instance.
Service not found
You are trying to call an action on a service that hasn't been created, registered, or is not available in the network.
fix
Verify the service name and action name are correct. Ensure the service is created with `broker.createService()` and the broker is started, allowing it to discover services across the network.
Upgrade
Version history
0.15.0latest on npm
Audit
Dependencies
amqpliboptionalRequired if using AMQP 0.9.1 as a transporter for message brokering.
natsoptionalRequired if using NATS as a transporter for high-performance messaging.
ioredisoptionalUsed for Redis-based transporters, caching, and distributed locking (via redlock).
pinooptionalOne of several pluggable loggers supported by Moleculer.
bunyanoptionalOne of several pluggable loggers supported by Moleculer.
winstonoptionalOne of several pluggable loggers supported by Moleculer.
cbor-xoptionalAn optional high-performance serializer for message encoding.
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
2
Resources