Interacting with user input in CLI is much different than GUI. In a CLI app you need to read the user-input using a node package. One such package is readline-sync. It allows the interaction of user with CLI through console.
How to use readlineSync in your code:
- First initialize npm(node package manager) in your repo -
- Install the readline package from npm in your repo/folder -
- Require the readline-sync module in your code -
- Now this readlineSync is ready to be used and perform different functions in your code.
//Simply Taking user Input and displaying it
console.log("Hi"+username);
OUTPUT:
//Acting to user Key Input through readlineSync and KeyIN
}
OUTPUT:
//Hiding user input for readline through hideEchoBack
console.log("Thanks for Signing In");
OUTPUT:
//Asking the user to choose input from a list
console.log("You will eat "+foodItems[index]+" today");
OUTPUT:
//handle user commands repeatedly similar to as shell interface handling
console.log("Exited");
OUTPUT:
Apart from these, there are many other functions that can be performed through readlineSync. Go the official Docs of the readline module.
Comments
Post a Comment