Created
July 23, 2021 14:56
-
-
Save themarcba/801f7a6b9bcd3df9cc9558fe9917506c to your computer and use it in GitHub Desktop.
This file contains 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
// A dependency-free, await-ready function for Node.js | |
// to get user input in the console | |
// Author: Marc Backes (@themarcba | |
const getInput = query => { | |
return new Promise((resolve, reject) => { | |
const readline = require('readline').createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}) | |
readline.question(`${query} `, answer => { | |
readline.close() | |
resolve(answer) | |
}) | |
}) | |
} | |
const run = async () => { | |
const name = await getInput(`What is your name?`) | |
console.log(`Your name is ${name}`) | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment