Moleculer Decorators
Decorators for moleculer
Available options
constructOverride: false
These are defined in @Service
Example usage
const moleculer = require('moleculer');
const { Service, Action, Event, Method } = require('moleculer-decorators');
const web = require('moleculer-web');
const broker = new moleculer.ServiceBroker({
logger: console,
logLevel: "debug",
});
@Service({
mixins: [web],
settings: {
port: 3000,
routes: [
...
]
}
})
class ServiceName {
constructor() {
this.settings = {
port: 3001
}
}
settings = {
port: 3001
}
@Action()
Login(ctx) {
...
}
@Action({
cache: false,
params: {
a: "number",
b: "number"
}
})
Login2(ctx) {
...
}
@Event
'event.name'(payload, sender, eventName) {
...
}
@Method
authorize(ctx, route, req, res) {
...
}
hello() {
...
}
started() {
...
}
created() {
...
}
stopped() {
...
}
}
broker.createService(ServiceName);
broker.start();
Usage with moleculer-runner
Simply export the service instead of starting a broker manually.
export = ServiceName
License
Moleculer Decorators is available under the MIT license.