Skip to content

Instantly share code, notes, and snippets.

@icebob
Last active February 15, 2020 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icebob/e92de0d536723086099a702c151db0fc to your computer and use it in GitHub Desktop.
Save icebob/e92de0d536723086099a702c151db0fc to your computer and use it in GitHub Desktop.
Moleculer quick example
const { ServiceBroker } = require("moleculer");
// Create broker
const broker = new ServiceBroker();
// Create a service
broker.createService({
name: "math",
actions: {
add(ctx) {
return Number(ctx.params.a) + Number(ctx.params.b);
}
}
});
// Start broker
broker.start()
// Call the service
.then(() => broker.call("math.add", { a: 5, b: 3 }))
.then(res => console.log("5 + 3 =", res));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment