Created
October 15, 2018 07:14
-
-
Save salmanx/82bee68bb9a8baed190c9f322960e40a to your computer and use it in GitHub Desktop.
snippet for standard input output example for node js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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