Install Moleculer Go

Moleculer can be installed with npm or yarn

$ go get -u

# Or with go modules v0.1.2

Create your first microservice

This example shows how to create a small math service to add two numbers.

package main

import (


var mathService = moleculer.Service{
Name: "math",
Actions: []moleculer.Action{
Name: "add",
Handler: func(ctx moleculer.Context, params moleculer.Payload) interface{} {
return params.Get("a").Int() + params.Get("b").Int()

func main() {
var bkr = broker.New(&moleculer.Config{LogLevel: "error"})
result := <-bkr.Call("math.add", payload.New(map[string]int{
"a": 10,
"b": 130,
fmt.Println("result: ", result.Int()) //$ result: 140

Try it!

$ go run

Create a Moleculer Go project

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

  1. Create a new project (named first-demo)

    $ moleculer init project first-demo

    Press Y to all questions

  2. Open project folder

    $ cd first-demo
  3. Start project

    $ go run .
  4. Open the http://localhost:3000/ link in your browser. It shows a start page which contains two links to call the greeter service via API gateway.


You have just created your first Moleculer-based microservices project! The next step is to check our examples or demo projects.