Skip to content

Instantly share code, notes, and snippets.

@Palisand
Created May 19, 2019 21:31
Show Gist options
  • Save Palisand/e341b0cb0696968d79d00125814f69d9 to your computer and use it in GitHub Desktop.
Save Palisand/e341b0cb0696968d79d00125814f69d9 to your computer and use it in GitHub Desktop.
// 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