Write a nodejs command line tool, providing various options, by moving up and down and then enter to choose, as shown in figure

  node.js, question


As shown in the figure, check the space, move the cursor up and down, press enter to confirm

Want to know how

It is rather troublesome to realize one by oneself, but fortunately there are enough “giants’ shoulders” in the open source world to step on.

You can refer to other node open source libraries. such asgruntyo, in the project initialization function, are providedQuestion and answerThis kind of function.

See how they do it.

  • Grunt: Through prompt, clickPortal

  • Yo: This is implemented through Inquirer.js. ClickPortal

AttachyoA screenshot of the initialization project