Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +40 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
or you could use a promise
```mjs
```mjs displayName="Promises API"

And change the other one accordingly

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}!`);

Comment on lines +50 to +53
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rl.close()
console.log(`Hi ${name}!`);
console.log(`Hi ${name}!`);
rl.close()

```

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
Loading