Created
August 14, 2025 10:02
-
-
Save lejonmanen/ee3fcd2c1671048c23053411497867a6 to your computer and use it in GitHub Desktop.
Node async readline
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
| /* Exempel på användning: | |
| import { ask } from './ask.ts' | |
| let x: string = await ask('Vilken är din favoritfärg? ') | |
| console.log('Du svarade: ' + x) | |
| */ | |
| import readline from 'node:readline' | |
| async function ask(query: string): Promise<string> { | |
| const rl = readline.createInterface({ input: process.stdin, output: process.stdout, tabSize: 4 }); | |
| return new Promise((resolve) => rl.question(query, (answer) => { | |
| rl.close(); | |
| resolve(answer); | |
| })); | |
| } | |
| export { ask } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment