Skip to content
Advertisement

NodeJS how to create a bash like input

I want to create a nodejs cli app, where there is a shell.

I have tried doing this so far:

JavaScript

But it only works once, how do I make it work continuously?

Like so:

JavaScript

Advertisement

Answer

That is happening because you are only calling the question function once. To ask for next input you need to call it again inside the callback. I would create a recursive function like this:

JavaScript

If you also need a command to exit out of question loop, you can even add a breaking condition like this

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement