Last active
February 15, 2020 17:09
-
-
Save icebob/e92de0d536723086099a702c151db0fc to your computer and use it in GitHub Desktop.
Moleculer quick example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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