Skip to content

Commit

Permalink
Update accept-input-from-the-command-line-in-nodejs.md to use a promise
Browse files Browse the repository at this point in the history
Signed-off-by: Benson Isaac  <[email protected]>
  • Loading branch information
heybosi authored Nov 20, 2024
1 parent 6be3b25 commit b424b15
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ rl.question(`What's your name?`, name => {
console.log(`Hi ${name}!`);
rl.close();
});
```
or you could use a promise
```mjs
import readline from "node:readline/promises";

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

const name = await rl.question("What's your name? ");
rl.close()

console.log(`Hi ${name}!`);

```

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

0 comments on commit b424b15

Please sign in to comment.