This version has reached end-of-life. It is no longer maintained. For the latest stable version, click here.

Command Line Tool

moleculer-cli npm

This is a command-line tool for Moleculer to help developing & testing.

Install

$ npm i -g moleculer-cli

Commands

Init a new project

With this command, you can scaffold a new Moleculer project.

$ moleculer init project my-project

The above command downloads the template from moleculerjs/moleculer-template-project, prompts some information and generates a new module to the ./my-project folder.

Official templates

  • project - Generate a common Moleculer-based project. Use it if you want to start a new project which is based on Moleculer framework
    • sample service (greeter)
    • official API Gateway (optional)
    • Docker & Docker Compose files
    • tests & coverage with Jest
    • lint with ESLint
  • nano - Minimal project template for one microservice. Use it if you want to create a microservice which connect to others via transporter
    • sample service (greeter)
    • Docker & Docker Compose files
    • tests & coverage with Jest
    • lint with ESLint
    • Minimal Docker file
  • module - Generate a new Moleculer module project (e.g.: moleculer-xyz). Use it if you want to create a module for Moleculer framework
    • empty service skeleton
    • examples skeleton
    • readme skeleton
    • tests & coverage with Jest
    • lint with ESLint

Custom templates

$ moleculer init username/repo my-project

Where username/repo is the GitHub repo shorthand for your fork.

The shorthand repo notation is passed to download-git-repo so you can also use things like bitbucket:username/repo for a Bitbucket repo and username/repo#branch for tags or branches.

Local Templates

Instead of a GitHub repo, use a template from local filesystem:

$ moleculer init ./path/to-custom-template my-project

Start a broker locally

This command starts a new ServiceBroker locally and switches to REPL mode.

$ moleculer start

Options

--config, -c   Load configuration from a file           [string] [default: ""]
--ns Namespace [string] [default: ""]
--id NodeID [string] [default: null]
--metrics, -m Enable metrics [boolean] [default: false]
--hot, -h Enable hot-reload [boolean] [default: false]
--cb Enable circuit breaker [boolean] [default: false]
--commands Custom REPL command file mask [string] [default: null]

Start a broker and connect to a transporter

This command starts a new ServiceBroker, connects to a transporter server and switches to REPL mode.

# Connect with TCP transporter
$ moleculer connect

# Connect to NATS
$ moleculer connect nats://localhost:4222

# Connect to Redis
$ moleculer connect redis://localhost

# Connect to MQTT
$ moleculer connect mqtt://localhost

# Connect to AMQP
$ moleculer connect amqp://localhost:5672

# Load all options from config file
$ moleculer connect --config ./moleculer.config.js

Options

--config, -c   Load configuration from a file           [string] [default: ""]
--ns Namespace [string] [default: ""]
--id NodeID [string] [default: null]
--metrics, -m Enable metrics [boolean] [default: false]
--hot, -h Enable hot-reload [boolean] [default: false]
--cb Enable circuit breaker [boolean] [default: false]
--serializer Serializer [string] [default: null]
--commands Custom REPL command file mask [string] [default: null]