Skip to content

Instantly share code, notes, and snippets.

@salmanx
Created October 15, 2018 07:14
Show Gist options
  • Save salmanx/82bee68bb9a8baed190c9f322960e40a to your computer and use it in GitHub Desktop.
Save salmanx/82bee68bb9a8baed190c9f322960e40a to your computer and use it in GitHub Desktop.
snippet for standard input output example for node js
const questions = [
"What is your name?",
"What is fav hobby?",
"What is your fav programming language?"
];
const answers = [];
function ask(i){
process.stdout.write(`\n\n ${questions[i]} \n\n`);
process.stdout.write(" > ");
}
process.stdin.on('data', function(data){
// process.stdout.write("\n\n" + data.toString().trim() + "\n\n");
answers.push(data.toString().trim());
if (answers.length < questions.length) {
ask(answers.length);
} else {
process.exit();
}
});
process.on('exit', function(){
process.stdout.write("\n\n\n\n");
process.stdout.write(`Go for ${answers[1]}, ${answers[0]}. You can finish ${answers[2]} later! `);
process.stdout.write("\n\n\n\n");
});
ask(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment