Moleculer: Consider JS-based REPL (instead of shell-like)

Created on 27 Apr 2018  路  1Comment  路  Source: moleculerjs/moleculer

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.

Now

Call an action

call greeter.welcome --name John
# or
call greeter.welcome '{"name": "John"}'

Work with action result

Not available.

JS alternative

This will get better when node repl gets await support.

Call an action

M.call('greeter.welcome', { name: 'John' })

Work with action result

_.then(r => r.toUpperCase()) // `_` is an alias for previous expression value
Low Enhancement help wanted

Most helpful comment

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!

>All comments

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!
Was this page helpful?
0 / 5 - 0 ratings

Related issues

HighSoftWare96 picture HighSoftWare96  路  4Comments

DeividasJackus picture DeividasJackus  路  4Comments

darky picture darky  路  5Comments

rozhddmi picture rozhddmi  路  4Comments

maitrucquynhq111 picture maitrucquynhq111  路  3Comments