Created
May 19, 2019 21:31
-
-
Save Palisand/e341b0cb0696968d79d00125814f69d9 to your computer and use it in GitHub Desktop.
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
// https://stackoverflow.com/a/54761452/3446870 | |
const {promisify} = require('util'); | |
const readline = require('readline'); | |
async function readlineQuestion(question) { | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
rl.question[promisify.custom] = (question) => { | |
return new Promise((resolve) => { | |
rl.question(question, resolve); | |
}) | |
}; | |
const answer = await promisify(rl.question)(question); | |
rl.close(); | |
return answer; | |
} | |
(async function () { | |
const answer = await readlineQuestion("What is the capital of Assyria?"); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment