Skip to content

Commit b424b15

Browse files
authored
Update accept-input-from-the-command-line-in-nodejs.md to use a promise
Signed-off-by: Benson Isaac <[email protected]>
1 parent 6be3b25 commit b424b15

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

apps/site/pages/en/learn/command-line/accept-input-from-the-command-line-in-nodejs.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ rl.question(`What's your name?`, name => {
3636
console.log(`Hi ${name}!`);
3737
rl.close();
3838
});
39+
```
40+
or you could use a promise
41+
```mjs
42+
import readline from "node:readline/promises";
43+
44+
const rl = readline.createInterface({
45+
input: process.stdin,
46+
output: process.stdout,
47+
});
48+
49+
const name = await rl.question("What's your name? ");
50+
rl.close()
51+
52+
console.log(`Hi ${name}!`);
53+
3954
```
4055

4156
This piece of code asks the user's _name_, and once the text is entered and the user presses enter, we send a greeting.

0 commit comments

Comments
 (0)