Skip to content

Commit 7eef2e3

Browse files
committed
add read line code
1 parent 9550693 commit 7eef2e3

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

04-process/03-read-line.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env node
2+
3+
const readline = require('readline/promises');
4+
const { stdin: input, stdout: output } = require('process');
5+
6+
const rl = readline.createInterface({ input, output });
7+
8+
const msg = ['Name', 'Email', 'QQ', 'Mobile'];
9+
let me = {};
10+
11+
async function main() {
12+
for(let i=0; i<4; i++) {
13+
const answer = await rl.question(msg[i] + ': ');
14+
me[msg[i]] = answer;
15+
}
16+
17+
rl.close();
18+
console.log(me);
19+
}
20+
21+
main();

04-process/03-std-io.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ stdin.on('data', (data) => {
2222
stdin.on('end', () => {
2323
log(me);
2424
});
25-

0 commit comments

Comments
 (0)