I often find myself running both moleculer REPL and a node one on two separate terminals, this makes for a really productive development environment in my opinion. But this leaves no (easy) way to transfer data back and forth.
What if instead moleculer REPL was built on node.js repl module with an extra exported global (or multiple globals)? Let's assume one global variable M for example.
call greeter.welcome --name John
# or
call greeter.welcome '{"name": "John"}'
Not available.
This will get better when node repl gets await support.
M.call('greeter.welcome', { name: 'John' })
_.then(r => r.toUpperCase()) // `_` is an alias for previous expression value
Good idea. I tried and you can use it with +1 extra line:
const { ServiceBroker } = require("moleculer");
const broker = new ServiceBroker({ logger: true });
broker.createService({
name: "greeter",
actions: {
hello(ctx) {
return "Hello!";
},
}
});
broker.start().then(() => require("repl").start("mol $ ").context.broker = broker);
Output:
mol $ broker.call("greeter.hello").then(console.log)
mol $ Hello!
Most helpful comment
Good idea. I tried and you can use it with +1 extra line:
Output: