2

I'm developing command line interface with node.js. Can we have custom console like mysql? Like, if we type mysql and enter in console it will come as mysql> so we can do all mysql related operation until we exit. Like that in node.js

> node hello
hello> help
hello> list apps
.
.
hello> exit
>
>node world
world>operation related to world
.
.
world>exit
> 
// or if it is executable
>hello
hello>help
hello>list app
hello>exit
>

It would be great if you give some suggestion.

2
  • 1
    Seems like you want to create a REPL. Check this out, though I haven't tried something lime it myself: How to create and use a custom REPL Commented Jul 7, 2015 at 21:20
  • Thanks for the link. I will look it out. Commented Jul 8, 2015 at 5:31

1 Answer 1

2

Yes. Check out Vorpal.js. It was made for this exact purpose.

var vorpal = require('vorpal')();

... // your app code

vorpal.command('list apps')
  .action(function (args, cb){
    var self = this;
    myapps.forEach(function(app) {
      self.log(app.name);
    });
    cb();
  });

vorpal
  .delimiter('hello>')
  .show();

And then you'll have this:

$ node hello.js
hello> list apps
..
..
hello>

Disclaimer: I wrote Vorpal.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.