Skip to content

Instantly share code, notes, and snippets.

@samandar-boymurodov
Created July 21, 2021 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samandar-boymurodov/7f42cb9fae8126d59a621ab2b464e0af to your computer and use it in GitHub Desktop.
Save samandar-boymurodov/7f42cb9fae8126d59a621ab2b464e0af to your computer and use it in GitHub Desktop.
Node JS readline module
const questions = [
"What is your favorite programming language?",
"Where do you work?",
"Do you like Node JS?"
]
const collectAnswers = (questions, done) => {
const readline = require("readline")
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
const answers = []
const answered = (answer) => {
answers.push(answer)
if (answers.length === questions.length) {
done(answers)
} else rl.question(questions[answers.length] + " ", answered)
}
rl.question(questions[0] + " ", answered)
}
collectAnswers(questions, answers => {
console.log("\nThank you for answering these questions :)")
console.log(`Your answers --> ${answers.join(" ")}`)
process.exit()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment