Last active
October 22, 2024 06:07
-
-
Save eeropic/48c6f9931805d5c47b371e8744bee6d4 to your computer and use it in GitHub Desktop.
simple prompt wrapper for nodejs readline
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
import readline from 'readline' | |
export const prompt = query => new Promise(resolve => { | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}) | |
rl.question(query, function(answer){ | |
resolve(answer) | |
rl.close() | |
}) | |
}) | |
// usage: | |
const answer = await prompt("How are you?\n>") | |
console.log(`You are ${answer}`) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment