Làm cách nào để đọc từng dòng tệp trong nodejs?

Bài viết này tập trung vào một số cách phổ biến để đọc tệp trong Node. js (cũng sử dụng TypeScript cho các ví dụ mã)

  1. import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    86 mô-đun gốc
  2. Thư viện npm mã nguồn mở
    import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    87

Một lỗi phổ biến khi đọc từng dòng tệp trong Node. js là đọc toàn bộ tệp vào bộ nhớ và sau đó chia nhỏ nội dung của nó bằng cách ngắt dòng. Làm điều này có thể làm quá tải hệ thống của bạn, đặc biệt là khi xử lý các tệp lớn

Đây là một tệp mẫu có nhiều dòng cần được xử lý từng dòng

# app.logLine 1
Line 2
Line 3
Line 4
Line 5
...

dòng đọc

Nút. js có một đường dẫn mô-đun gốc cung cấp giao diện để đọc dữ liệu từ luồng một dòng tại một thời điểm

Chúng tôi có thể sử dụng hành vi này để đọc từ luồng tệp và xử lý từng dòng riêng biệt

Về cơ bản, các bước để đạt được điều này là

  1. tạo đối tượng realine bằng hàm
    import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    88. Trong khi thực hiện việc này, chúng tôi phải cung cấp luồng tệp
  2. liên kết người nghe với sự kiện
    import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    89

Đoạn mã sau sử dụng Node. js gốc mô-đun

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
86 để đọc tệp trên thành một luồng và in từng dòng

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}

Gọi hàm

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
1 tạo đầu ra sau

ConsoleLine 1
Line 2
Line 3
Line 4
Line 5
...

Cách tiếp cận này vượt trội so với

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
2 thông thường mặc dù Node. js vẫn cố giữ toàn bộ tệp trong bộ nhớ khi truyền tệp đầu vào sang đầu ra

Chúng tôi sẽ cần một giải pháp mới nếu bạn có một tệp thực sự lớn để xử lý từng dòng một

Luồng sự kiện

EventStream là một thư viện NPM phổ biến hứa hẹn sẽ giúp việc tạo và làm việc với các luồng trở nên dễ dàng

Để sử dụng EventStream, hãy cài đặt bằng npm

npm i --save-exact event-stream

Tùy chọn, để cài đặt các loại

npm i --save-exact --save-dev @types/event-stream

Khi EventStream được cài đặt, chúng tôi sẽ chỉ chuyển luồng đọc tới người nghe để đọc từng dòng tệp

Dưới đây là đoạn mã sử dụng ________ 13 để đạt được điều tương tự như đoạn mã trong đoạn mã ________ 486 ở trên

________số 8

Phần kết luận

Ở đây tôi đã trình bày hai cách khác nhau để đọc từng dòng tệp, một cách có nút. js và một mô-đun khác với thư viện mã nguồn mở phổ biến

Chọn một trong các phương pháp tùy thuộc vào nhu cầu của bạn. Và nếu kích thước dữ liệu lớn, bạn nên sử dụng thư viện EventStream để không làm hỏng máy chủ Node

Mô-đun

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
2 cung cấp giao diện để đọc dữ liệu từ luồng Có thể đọc (chẳng hạn như
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
3) mỗi lần một dòng

Để sử dụng các API dựa trên lời hứa

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
1

Để sử dụng API gọi lại và đồng bộ hóa

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
2

Ví dụ đơn giản sau đây minh họa cách sử dụng cơ bản của mô-đun

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
2

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();

Khi mã này được gọi, Nút. ứng dụng js sẽ không kết thúc cho đến khi đóng

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
5 vì giao diện chờ nhận dữ liệu trên luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6

Tầng lớp. import * as readline from 'node:readline/promises'; import { stdin as input, stdout as output } from 'node:process'; const rl = readline.createInterface({ input, output }); const answer = await rl.question('What do you think of Node.js? '); console.log(`Thank you for your valuable feedback: ${answer}`); rl.close();7#

Các thể hiện của lớp

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
7 được xây dựng bằng phương thức
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
9 hoặc
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
00. Mọi phiên bản được liên kết với một luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 Có thể đọc và một luồng duy nhất
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
02 Có thể ghi. Luồng
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
02 được sử dụng để in lời nhắc cho đầu vào của người dùng xuất hiện và được đọc từ luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6

Biến cố.
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
05#

Sự kiện

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
05 được phát ra khi một trong những điều sau đây xảy ra

  • Phương thức
    import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    07 được gọi và thực thể
    import * as readline from 'node:readline/promises';
    import { stdin as input, stdout as output } from 'node:process';
    
    const rl = readline.createInterface({ input, output });
    
    const answer = await rl.question('What do you think of Node.js? ');
    
    console.log(`Thank you for your valuable feedback: ${answer}`);
    
    rl.close();
    7 đã từ bỏ quyền kiểm soát đối với các luồng
    import * as readline from 'node:readline/promises';
    import { stdin as input, stdout as output } from 'node:process';
    
    const rl = readline.createInterface({ input, output });
    
    const answer = await rl.question('What do you think of Node.js? ');
    
    console.log(`Thank you for your valuable feedback: ${answer}`);
    
    rl.close();
    6 và
    import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    02;
  • Luồng
    import * as readline from 'node:readline/promises';
    import { stdin as input, stdout as output } from 'node:process';
    
    const rl = readline.createInterface({ input, output });
    
    const answer = await rl.question('What do you think of Node.js? ');
    
    console.log(`Thank you for your valuable feedback: ${answer}`);
    
    rl.close();
    6 nhận sự kiện
    ConsoleLine 1
    Line 2
    Line 3
    Line 4
    Line 5
    ...
    22 của nó;
  • Luồng
    import * as readline from 'node:readline/promises';
    import { stdin as input, stdout as output } from 'node:process';
    
    const rl = readline.createInterface({ input, output });
    
    const answer = await rl.question('What do you think of Node.js? ');
    
    console.log(`Thank you for your valuable feedback: ${answer}`);
    
    rl.close();
    6 nhận Ctrl+D để báo hiệu kết thúc truyền (EOT);
  • Luồng
    import * as readline from 'node:readline/promises';
    import { stdin as input, stdout as output } from 'node:process';
    
    const rl = readline.createInterface({ input, output });
    
    const answer = await rl.question('What do you think of Node.js? ');
    
    console.log(`Thank you for your valuable feedback: ${answer}`);
    
    rl.close();
    6 nhận Ctrl+C để báo hiệu
    ConsoleLine 1
    Line 2
    Line 3
    Line 4
    Line 5
    ...
    25 và không có trình xử lý sự kiện
    ConsoleLine 1
    Line 2
    Line 3
    Line 4
    Line 5
    ...
    26 nào được đăng ký trên phiên bản
    import * as readline from 'node:readline/promises';
    import { stdin as input, stdout as output } from 'node:process';
    
    const rl = readline.createInterface({ input, output });
    
    const answer = await rl.question('What do you think of Node.js? ');
    
    console.log(`Thank you for your valuable feedback: ${answer}`);
    
    rl.close();
    7

Hàm nghe được gọi mà không truyền bất kỳ đối số nào

Phiên bản

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
7 kết thúc sau khi sự kiện
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
05 được phát ra

Biến cố.
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
00#

Sự kiện

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
00 được phát ra bất cứ khi nào luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 nhận được đầu vào cuối dòng (
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
03,
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
04 hoặc
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
05). Điều này thường xảy ra khi người dùng nhấn Enter hoặc Return

Sự kiện

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
00 cũng được phát ra nếu dữ liệu mới đã được đọc từ một luồng và luồng đó kết thúc mà không có điểm đánh dấu cuối dòng cuối cùng

Hàm nghe được gọi với một chuỗi chứa một dòng đầu vào nhận được

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
0

Biến cố.
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
07#

Đã thêm vào. v15. 8. 0, v14. 18. 0

Sự kiện

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
07 được phát ra bất cứ khi nào mảng lịch sử thay đổi

Hàm nghe được gọi với một mảng chứa mảng lịch sử. Nó sẽ phản ánh tất cả các thay đổi, các dòng được thêm và các dòng bị xóa do

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
09 và
npm i --save-exact event-stream
10

Mục đích chính là cho phép người nghe lưu lại lịch sử. Người nghe cũng có thể thay đổi đối tượng lịch sử. Điều này có thể hữu ích để ngăn một số dòng nhất định được thêm vào lịch sử, chẳng hạn như mật khẩu

ConsoleLine 1
Line 2
Line 3
Line 4
Line 5
...
2

Biến cố.
npm i --save-exact event-stream
11#

Sự kiện

npm i --save-exact event-stream
11 được phát ra khi một trong những điều sau đây xảy ra

  • Luồng
    import * as readline from 'node:readline/promises';
    import { stdin as input, stdout as output } from 'node:process';
    
    const rl = readline.createInterface({ input, output });
    
    const answer = await rl.question('What do you think of Node.js? ');
    
    console.log(`Thank you for your valuable feedback: ${answer}`);
    
    rl.close();
    6 bị tạm dừng
  • Luồng
    import * as readline from 'node:readline/promises';
    import { stdin as input, stdout as output } from 'node:process';
    
    const rl = readline.createInterface({ input, output });
    
    const answer = await rl.question('What do you think of Node.js? ');
    
    console.log(`Thank you for your valuable feedback: ${answer}`);
    
    rl.close();
    6 không bị tạm dừng và nhận sự kiện
    npm i --save-exact event-stream
    15. (Xem sự kiện
    npm i --save-exact event-stream
    16 và
    npm i --save-exact event-stream
    15. )

Hàm nghe được gọi mà không truyền bất kỳ đối số nào

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
0

Biến cố.
npm i --save-exact event-stream
18#

Sự kiện

npm i --save-exact event-stream
18 được phát ra bất cứ khi nào luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 được tiếp tục

Hàm nghe được gọi mà không truyền bất kỳ đối số nào

npm i --save-exact event-stream
1

Biến cố.
npm i --save-exact event-stream
15#

Sự kiện

npm i --save-exact event-stream
15 được phát ra khi một Nút. js trước đó đã được di chuyển vào nền bằng cách sử dụng Ctrl+Z (i. e.
npm i --save-exact --save-dev @types/event-stream
73) sau đó được đưa trở lại nền trước bằng cách sử dụng
npm i --save-exact --save-dev @types/event-stream
74

Nếu luồng

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 bị tạm dừng trước yêu cầu
npm i --save-exact --save-dev @types/event-stream
73, thì sự kiện này sẽ không được phát ra

Hàm nghe được gọi mà không truyền bất kỳ đối số nào

Sự kiện

npm i --save-exact event-stream
15 không được hỗ trợ trên Windows

Biến cố.
ConsoleLine 1
Line 2
Line 3
Line 4
Line 5
...
26#

Sự kiện

ConsoleLine 1
Line 2
Line 3
Line 4
Line 5
...
26 được phát ra bất cứ khi nào luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 nhận được đầu vào Ctrl+C, thường được gọi là
ConsoleLine 1
Line 2
Line 3
Line 4
Line 5
...
25. Nếu không có trình lắng nghe sự kiện
ConsoleLine 1
Line 2
Line 3
Line 4
Line 5
...
26 nào được đăng ký khi luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 nhận được một
ConsoleLine 1
Line 2
Line 3
Line 4
Line 5
...
25, thì sự kiện
npm i --save-exact event-stream
11 sẽ được phát ra

Hàm nghe được gọi mà không truyền bất kỳ đối số nào

npm i --save-exact --save-dev @types/event-stream
7

Biến cố.
npm i --save-exact event-stream
16#

Sự kiện

npm i --save-exact event-stream
16 được phát ra khi luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 nhận được đầu vào Ctrl+Z, thường được gọi là
npm i --save-exact --save-dev @types/event-stream
73. Nếu không có trình lắng nghe sự kiện
npm i --save-exact event-stream
16 nào được đăng ký khi luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 nhận được một
npm i --save-exact --save-dev @types/event-stream
73, nút. js sẽ được gửi đến nền

Khi chương trình được tiếp tục sử dụng

npm i --save-exact --save-dev @types/event-stream
74, các sự kiện
npm i --save-exact event-stream
11 và
npm i --save-exact event-stream
15 sẽ được phát ra. Chúng có thể được sử dụng để tiếp tục luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6

Các sự kiện

npm i --save-exact event-stream
11 và
npm i --save-exact event-stream
15 sẽ không được phát ra nếu
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 bị tạm dừng trước khi quá trình được gửi đến nền

Hàm nghe được gọi mà không truyền bất kỳ đối số nào

Sự kiện

npm i --save-exact event-stream
16 không được hỗ trợ trên Windows

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
07#

Phương thức

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
07 đóng phiên bản
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
7 và từ bỏ quyền kiểm soát đối với các luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 và
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
02. Khi được gọi, sự kiện
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
05 sẽ được phát ra

Việc gọi

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
07 không ngay lập tức ngăn chặn các sự kiện khác (bao gồm cả
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
00) được phát ra bởi phiên bản
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
7

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
210#

Phương thức

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
210 tạm dừng luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6, cho phép tiếp tục lại sau nếu cần

Việc gọi

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
210 không tạm dừng ngay lập tức các sự kiện khác (bao gồm cả
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
00) do phiên bản
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
7 phát ra

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
216#

  • import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    217 Nếu
    import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    218, ngăn không cho đặt lại vị trí con trỏ thành
    import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    219

Phương thức

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
220 ghi các phiên bản
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
7 được định cấu hình
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
222 vào một dòng mới trong
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
02 để cung cấp cho người dùng một vị trí mới để cung cấp đầu vào

Khi được gọi,

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
220 sẽ tiếp tục luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 nếu nó đã bị tạm dừng

Nếu

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
7 được tạo với
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
02 được đặt thành
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
228 hoặc
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
229 thì lời nhắc sẽ không được viết

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
230#

Phương thức

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
230 tiếp tục luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 nếu nó đã bị tạm dừng

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
233#

Phương thức

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
234 đặt lời nhắc sẽ được ghi vào
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
02 bất cứ khi nào
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
220 được gọi

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
237#

Đã thêm vào. v15. 3. 0, v14. 17. 0

  • trả lại. chuỗi dấu nhắc hiện tại

Phương thức

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
237 trả về lời nhắc hiện tại được sử dụng bởi
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
220

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
240#

Phương thức

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
241 sẽ ghi
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
242 hoặc một chuỗi khóa được xác định bởi
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
243 vào
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
02. Đối số
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
243 chỉ được hỗ trợ nếu
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
02 là thiết bị đầu cuối văn bản TTY. Xem tổ hợp phím TTY để biết danh sách tổ hợp phím

Nếu

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
243 được chỉ định, thì
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
242 sẽ bị bỏ qua

Khi được gọi,

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
241 sẽ tiếp tục luồng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 nếu nó đã bị tạm dừng

Nếu

import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
7 được tạo với
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
02 được đặt thành
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
228 hoặc
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
229 thì
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
242 và
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
243 không được viết

Phương thức

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
241 sẽ ghi dữ liệu vào
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
6 của
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
258
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
259 như thể nó được cung cấp bởi người dùng

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
261#

Lịch sửPhiên bảnChangesv11. 14. 0, v10. 17. 0

Biểu tượng. hỗ trợ asyncIterator không còn thử nghiệm

v11. 4. 0, v10. 16. 0

Đã thêm vào. v11. 4. 0, v10. 16. 0

Tạo đối tượng

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
262 lặp qua từng dòng trong luồng đầu vào dưới dạng chuỗi. Phương thức này cho phép lặp không đồng bộ các đối tượng
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
7 thông qua các vòng lặp
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
264

Lỗi trong luồng đầu vào không được chuyển tiếp

Nếu vòng lặp kết thúc bằng

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
265,
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
266 hoặc
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
267, thì
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
07 sẽ được gọi. Nói cách khác, việc lặp lại trên một
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';

const rl = readline.createInterface({ input, output });

const answer = await rl.question('What do you think of Node.js? ');

console.log(`Thank you for your valuable feedback: ${answer}`);

rl.close();
7 sẽ luôn sử dụng đầy đủ luồng đầu vào

Hiệu suất không ngang bằng với API sự kiện

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
00 truyền thống. Thay vào đó, hãy sử dụng
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
00 cho các ứng dụng nhạy cảm với hiệu suất

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
00 sẽ bắt đầu sử dụng luồng đầu vào sau khi được gọi. Có các hoạt động không đồng bộ giữa tạo giao diện và lặp lại không đồng bộ có thể dẫn đến bỏ sót dòng

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
273#

Lịch sửPhiên bảnThay đổiv15. 8. 0, v14. 18. 0

Giá trị sẽ luôn là một chuỗi, không bao giờ được xác định

v0. 1. 98

Đã thêm vào. v0. 1. 98

Dữ liệu đầu vào hiện tại đang được nút xử lý

Điều này có thể được sử dụng khi thu thập đầu vào từ luồng TTY để truy xuất giá trị hiện tại đã được xử lý cho đến nay, trước khi sự kiện

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
274 được phát ra. Khi sự kiện
import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
274 đã được phát ra, thuộc tính này sẽ là một chuỗi rỗng

Xin lưu ý rằng việc sửa đổi giá trị trong thời gian chạy phiên bản có thể gây ra những hậu quả ngoài ý muốn nếu

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
276 cũng không được kiểm soát

Nếu không sử dụng luồng TTY cho đầu vào, hãy sử dụng sự kiện

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
00

Một trường hợp sử dụng có thể sẽ như sau

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
73

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
276#

Vị trí con trỏ so với

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
273

Điều này sẽ theo dõi vị trí của con trỏ hiện tại trong chuỗi đầu vào, khi đọc đầu vào từ luồng TTY. Vị trí của con trỏ xác định phần của chuỗi đầu vào sẽ được sửa đổi khi đầu vào được xử lý, cũng như cột nơi dấu mũ đầu cuối sẽ được hiển thị

import { createReadStream } from 'fs'
import { createInterface } 'readline'
const readFile = () => { // Step 1
const rlInterface = createInterface({
input: createReadStream('app.log'),
output: process.stdout,
terminal: false // to indicate this is not TTY
})
// Step 2
rlInterface.on('line', (line) => {
console.log(line)
})
}
280#

Đã thêm vào. v13. 5. 0, v12. 16. 0

  • trả lại.
    • import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      281 hàng của dấu nhắc mà con trỏ hiện đang dừng lại
    • import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      282 cột màn hình mà con trỏ hiện đang dừng trên đó

    Trả về vị trí thực của con trỏ liên quan đến dấu nhắc đầu vào + chuỗi. Chuỗi đầu vào (gói) dài, cũng như lời nhắc nhiều dòng được đưa vào tính toán

    API hứa hẹn #

    Tầng lớp.
    import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    283#

    Các thể hiện của lớp

    import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    283 được xây dựng bằng phương thức
    import * as readline from 'node:readline/promises';
    import { stdin as input, stdout as output } from 'node:process';
    
    const rl = readline.createInterface({ input, output });
    
    const answer = await rl.question('What do you think of Node.js? ');
    
    console.log(`Thank you for your valuable feedback: ${answer}`);
    
    rl.close();
    9. Mọi phiên bản được liên kết với một luồng
    import * as readline from 'node:readline/promises';
    import { stdin as input, stdout as output } from 'node:process';
    
    const rl = readline.createInterface({ input, output });
    
    const answer = await rl.question('What do you think of Node.js? ');
    
    console.log(`Thank you for your valuable feedback: ${answer}`);
    
    rl.close();
    6 Có thể đọc và một luồng duy nhất
    import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    02 Có thể ghi. Luồng
    import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    02 được sử dụng để in lời nhắc cho đầu vào của người dùng xuất hiện và được đọc từ luồng
    import * as readline from 'node:readline/promises';
    import { stdin as input, stdout as output } from 'node:process';
    
    const rl = readline.createInterface({ input, output });
    
    const answer = await rl.question('What do you think of Node.js? ');
    
    console.log(`Thank you for your valuable feedback: ${answer}`);
    
    rl.close();
    6

    import { createReadStream } from 'fs'
    import { createInterface } 'readline'
    const readFile = () => { // Step 1
    const rlInterface = createInterface({
    input: createReadStream('app.log'),
    output: process.stdout,
    terminal: false // to indicate this is not TTY
    })
    // Step 2
    rlInterface.on('line', (line) => {
    console.log(line)
    })
    }
    290#
    • import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      291 Một câu lệnh hoặc truy vấn để viết cho
      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      02, được đặt trước dấu nhắc
    • import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      293
      • import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        294 ​​Tùy chọn cho phép hủy bỏ
        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        295 bằng cách sử dụng
        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        296
    • trả lại. Một lời hứa được thực hiện với đầu vào của người dùng để đáp lại
      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      291
    • Phương thức

      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      298 hiển thị
      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      291 bằng cách ghi nó vào
      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      02, đợi đầu vào của người dùng được cung cấp trên
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      6, sau đó gọi hàm
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      02 chuyển đầu vào được cung cấp làm đối số đầu tiên

      Khi được gọi,

      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      298 sẽ tiếp tục luồng
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      6 nếu nó đã bị tạm dừng

      Nếu

      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      283 được tạo với
      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      02 được đặt thành
      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      228 hoặc
      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      229 thì
      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      291 không được viết

      Nếu câu hỏi được gọi sau

      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      07, nó sẽ trả về một lời hứa bị từ chối

      Ví dụ sử dụng

      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      07

      Sử dụng

      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      296 để hủy câu hỏi

      import { createReadStream } from 'fs'
      import { createInterface } 'readline'
      const readFile = () => { // Step 1
      const rlInterface = createInterface({
      input: createReadStream('app.log'),
      output: process.stdout,
      terminal: false // to indicate this is not TTY
      })
      // Step 2
      rlInterface.on('line', (line) => {
      console.log(line)
      })
      }
      20

      Tầng lớp.
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      12#

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      13#
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      14#
      • import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        15
        • import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          16. sang trái từ con trỏ
        • import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          17. sang phải từ con trỏ
        • import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          219. toàn bộ dòng
      • trả lại. cái này

      Phương pháp

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      19 thêm vào danh sách nội bộ của hành động đang chờ xử lý, một hành động xóa dòng hiện tại của
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      20 được liên kết theo một hướng cụ thể được xác định bởi
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      15. Gọi
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      22 để xem tác dụng của phương thức này, trừ khi
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      23 được truyền cho hàm tạo

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      24#

      Phương thức

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      24 thêm vào danh sách nội bộ của hành động đang chờ xử lý, một hành động xóa luồng được liên kết từ vị trí hiện tại của con trỏ xuống. Gọi
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      22 để xem tác dụng của phương thức này, trừ khi
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      23 được truyền cho hàm tạo

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      22#

      Phương thức

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      22 gửi tất cả các hành động đang chờ xử lý đến
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      20 được liên kết và xóa danh sách nội bộ các hành động đang chờ xử lý

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      31#

      Phương thức

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      32 thêm vào danh sách nội bộ của hành động đang chờ xử lý, một hành động di chuyển con trỏ đến vị trí đã chỉ định trong
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      20 được liên kết. Gọi
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      22 để xem tác dụng của phương thức này, trừ khi
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      23 được truyền cho hàm tạo

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      36#

      Phương thức

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      37 thêm vào danh sách nội bộ của hành động đang chờ xử lý, một hành động di chuyển con trỏ so với vị trí hiện tại của nó trong
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      20 được liên kết. Gọi
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      22 để xem tác dụng của phương thức này, trừ khi
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      23 được truyền cho hàm tạo

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      41#

      Các phương thức

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      42 xóa danh sách nội bộ của các hành động đang chờ xử lý mà không gửi nó đến
      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      20 được liên kết

      import * as readline from 'node:readline/promises';
      import { stdin as input, stdout as output } from 'node:process';
      
      const rl = readline.createInterface({ input, output });
      
      const answer = await rl.question('What do you think of Node.js? ');
      
      console.log(`Thank you for your valuable feedback: ${answer}`);
      
      rl.close();
      44#

      • import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        293
        • import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          6 Luồng có thể đọc để nghe. Tùy chọn này là bắt buộc
        • import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          02 Luồng có thể ghi để ghi dữ liệu dòng đọc vào
        • import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          48 Một chức năng tùy chọn được sử dụng để tự động hoàn thành Tab
        • import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          49
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          218 nếu luồng
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          6 và
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          02 phải được coi như TTY và có mã thoát ANSI/VT100 được ghi vào đó. Vỡ nợ. kiểm tra
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          53 trên luồng
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          02 khi khởi tạo
        • import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          55 Danh sách ban đầu của các dòng lịch sử. Tùy chọn này chỉ có ý nghĩa nếu người dùng đặt
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          49 thành
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          218 hoặc bằng cách kiểm tra nội bộ
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          02, nếu không thì cơ chế lưu vào bộ nhớ đệm lịch sử hoàn toàn không được khởi tạo. Vỡ nợ.
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          59
        • import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          09 Số dòng lịch sử tối đa được giữ lại. Để tắt lịch sử, hãy đặt giá trị này thành
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          219. Tùy chọn này chỉ có ý nghĩa nếu người dùng đặt
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          49 thành
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          218 hoặc bằng cách kiểm tra nội bộ
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          02, nếu không thì cơ chế lưu vào bộ nhớ đệm lịch sử hoàn toàn không được khởi tạo. Vỡ nợ.
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          65
        • npm i --save-exact event-stream
          10 Nếu
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          218, khi một dòng đầu vào mới được thêm vào danh sách lịch sử trùng lặp với một dòng cũ hơn, thao tác này sẽ xóa dòng cũ hơn khỏi danh sách. Vỡ nợ.
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          68
        • import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          222 Chuỗi dấu nhắc sử dụng. Vỡ nợ.
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          70
        • import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          71 Nếu độ trễ giữa
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          04 và
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          03 vượt quá
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          71 mili giây, cả
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          04 và
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          03 sẽ được coi là đầu vào cuối dòng riêng biệt.
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          71 sẽ bị cưỡng chế đến một con số không ít hơn
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          78. Nó có thể được đặt thành
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          79, trong trường hợp đó,
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          04 theo sau bởi
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          03 sẽ luôn được coi là một dòng mới (có thể hợp lý để đọc các tệp có dấu phân cách dòng
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          05). Vỡ nợ.
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          78
        • import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          84 Khoảng thời gian
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          85 sẽ đợi một ký tự (khi đọc một chuỗi khóa không rõ ràng tính bằng mili giây, một chuỗi có thể tạo thành một chuỗi khóa hoàn chỉnh bằng cách sử dụng đầu vào đã đọc cho đến nay và có thể nhận thêm đầu vào để hoàn thành một chuỗi khóa dài hơn). Vỡ nợ.
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          86
        • import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          87 Số khoảng trắng của một tab bằng (tối thiểu 1). Vỡ nợ.
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          88
      • trả lại.
      • Phương thức

        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        9 tạo một thể hiện
        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        283 mới

        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        21

        Khi phiên bản

        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        283 được tạo, trường hợp phổ biến nhất là lắng nghe sự kiện
        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        00

        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        22

        Nếu

        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        49 là
        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        218 đối với trường hợp này thì luồng
        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        02 sẽ có khả năng tương thích tốt nhất nếu nó xác định thuộc tính
        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        96 và phát ra sự kiện
        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        97 trên
        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        02 nếu hoặc khi các cột thay đổi (
        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        99 tự động thực hiện việc này khi là TTY)

        Sử dụng hàm
        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        48#

        Hàm

        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        48 lấy dòng hiện tại do người dùng nhập làm đối số và trả về một
        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        002 với 2 mục nhập

        • Một
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          002 với các mục phù hợp để hoàn thành
        • Chuỗi con đã được sử dụng để so khớp

        Ví dụ.

        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        004

        Hàm

        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        48 cũng có thể trả về a hoặc không đồng bộ

        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        23

        API gọi lại #

        Tầng lớp.
        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        5#

        Lịch sửPhiên bảnThay đổiv17. 0. 0

        Lớp

        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        5 hiện kế thừa từ
        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        259

        v0. 1. 104

        Đã thêm vào. v0. 1. 104

        Các thể hiện của lớp

        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        5 được xây dựng bằng phương thức
        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        00. Mọi phiên bản được liên kết với một luồng
        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        6 Có thể đọc và một luồng duy nhất
        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        02 Có thể ghi. Luồng
        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        02 được sử dụng để in lời nhắc cho đầu vào của người dùng xuất hiện và được đọc từ luồng
        import * as readline from 'node:readline/promises';
        import { stdin as input, stdout as output } from 'node:process';
        
        const rl = readline.createInterface({ input, output });
        
        const answer = await rl.question('What do you think of Node.js? ');
        
        console.log(`Thank you for your valuable feedback: ${answer}`);
        
        rl.close();
        6

        import { createReadStream } from 'fs'
        import { createInterface } 'readline'
        const readFile = () => { // Step 1
        const rlInterface = createInterface({
        input: createReadStream('app.log'),
        output: process.stdout,
        terminal: false // to indicate this is not TTY
        })
        // Step 2
        rlInterface.on('line', (line) => {
        console.log(line)
        })
        }
        015#
        • import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          291 Một câu lệnh hoặc truy vấn để viết cho
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          02, được đặt trước dấu nhắc
        • import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          293
          • import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            294 ​​Tùy chọn cho phép hủy bỏ
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            295 bằng cách sử dụng
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            021
        • import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          02 Một chức năng gọi lại được gọi với đầu vào của người dùng để đáp lại
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          291
        • Phương thức

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          298 hiển thị
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          291 bằng cách ghi nó vào
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          02, đợi đầu vào của người dùng được cung cấp trên
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          6, sau đó gọi hàm
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          02 chuyển đầu vào được cung cấp làm đối số đầu tiên

          Khi được gọi,

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          298 sẽ tiếp tục luồng
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          6 nếu nó đã bị tạm dừng

          Nếu

          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          5 được tạo với
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          02 được đặt thành
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          228 hoặc
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          229 thì
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          291 không được viết

          Hàm

          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          02 được truyền cho
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          298 không tuân theo mẫu điển hình là chấp nhận một đối tượng
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          038 hoặc
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          228 làm đối số đầu tiên.
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          02 được gọi với câu trả lời được cung cấp làm đối số duy nhất

          Sẽ xảy ra lỗi nếu gọi

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          298 sau
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          07

          Ví dụ sử dụng

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          24

          Sử dụng

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          021 để hủy câu hỏi

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          25

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          044#

          Lịch sửPhiên bảnThay đổiv18. 0. 0

          Chuyển một cuộc gọi lại không hợp lệ cho đối số

          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          02 giờ đây ném
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          046 thay vì
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          047

          v12. 7. 0

          Giá trị trả về và gọi lại write() của luồng được hiển thị

          v0. 7. 7

          Đã thêm vào. v0. 7. 7

          • import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            20
          • import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            15
            • import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              16. sang trái từ con trỏ
            • import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              17. sang phải từ con trỏ
            • import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              219. toàn bộ dòng
          • import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            02 Được gọi sau khi thao tác hoàn tất
          • trả lại. ________ 968 nếu ________ 920 muốn mã gọi chờ sự kiện ________ 2056 được phát ra trước khi tiếp tục ghi dữ liệu bổ sung;

          Phương pháp

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          058 xóa dòng hiện tại của luồng TTY đã cho theo một hướng cụ thể được xác định bởi
          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          15

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          060#

          Lịch sửPhiên bảnThay đổiv18. 0. 0

          Chuyển một cuộc gọi lại không hợp lệ cho đối số

          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          02 giờ đây ném
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          046 thay vì
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          047

          v12. 7. 0

          Giá trị trả về và gọi lại write() của luồng được hiển thị

          v0. 7. 7

          Đã thêm vào. v0. 7. 7

          • import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            20
          • import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            02 Được gọi sau khi thao tác hoàn tất
          • trả lại. ________ 968 nếu ________ 920 muốn mã gọi chờ sự kiện ________ 2056 được phát ra trước khi tiếp tục ghi dữ liệu bổ sung;

          Phương thức

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          070 xóa luồng TTY đã cho từ vị trí hiện tại của con trỏ xuống

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          071#

          Lịch sửPhiên bảnThay đổiv15. 14. 0, v14. 18. 0

          Tùy chọn

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          294 ​​hiện được hỗ trợ

          v15. 8. 0, v14. 18. 0

          Tùy chọn

          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          55 hiện được hỗ trợ

          v13. 9. 0

          Tùy chọn

          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          87 hiện được hỗ trợ

          v8. 3. 0, v6. 11. 4

          Xóa giới hạn tối đa của tùy chọn

          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          71

          v6. 6. 0

          Tùy chọn

          import * as readline from 'node:readline/promises';
          import { stdin as input, stdout as output } from 'node:process';
          
          const rl = readline.createInterface({ input, output });
          
          const answer = await rl.question('What do you think of Node.js? ');
          
          console.log(`Thank you for your valuable feedback: ${answer}`);
          
          rl.close();
          71 hiện được hỗ trợ

          v6. 3. 0

          Tùy chọn

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          222 hiện được hỗ trợ

          v6. 0. 0

          Tùy chọn

          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          09 có thể là
          import { createReadStream } from 'fs'
          import { createInterface } 'readline'
          const readFile = () => { // Step 1
          const rlInterface = createInterface({
          input: createReadStream('app.log'),
          output: process.stdout,
          terminal: false // to indicate this is not TTY
          })
          // Step 2
          rlInterface.on('line', (line) => {
          console.log(line)
          })
          }
          219 ngay bây giờ

          v0. 1. 98

          Đã thêm vào. v0. 1. 98

          • import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            293
            • import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              6 Luồng có thể đọc để nghe. Tùy chọn này là bắt buộc
            • import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              02 Luồng có thể ghi để ghi dữ liệu dòng đọc vào
            • import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              48 Một chức năng tùy chọn được sử dụng để tự động hoàn thành Tab
            • import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              49
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              218 nếu luồng
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              6 và
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              02 phải được coi như TTY và có mã thoát ANSI/VT100 được ghi vào đó. Vỡ nợ. kiểm tra
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              53 trên luồng
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              02 khi khởi tạo
            • import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              55 Danh sách ban đầu của các dòng lịch sử. Tùy chọn này chỉ có ý nghĩa nếu người dùng đặt
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              49 thành
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              218 hoặc bằng cách kiểm tra nội bộ
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              02, nếu không thì cơ chế lưu vào bộ nhớ đệm lịch sử hoàn toàn không được khởi tạo. Vỡ nợ.
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              59
            • import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              09 Số dòng lịch sử tối đa được giữ lại. Để tắt lịch sử, hãy đặt giá trị này thành
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              219. Tùy chọn này chỉ có ý nghĩa nếu người dùng đặt
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              49 thành
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              218 hoặc bằng cách kiểm tra nội bộ
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              02, nếu không thì cơ chế lưu vào bộ nhớ đệm lịch sử hoàn toàn không được khởi tạo. Vỡ nợ.
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              65
            • npm i --save-exact event-stream
              10 Nếu
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              218, khi một dòng đầu vào mới được thêm vào danh sách lịch sử trùng lặp với một dòng cũ hơn, thao tác này sẽ xóa dòng cũ hơn khỏi danh sách. Vỡ nợ.
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              68
            • import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              222 Chuỗi dấu nhắc sử dụng. Vỡ nợ.
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              70
            • import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              71 Nếu độ trễ giữa
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              04 và
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              03 vượt quá
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              71 mili giây, cả
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              04 và
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              03 sẽ được coi là đầu vào cuối dòng riêng biệt.
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              71 sẽ bị cưỡng chế đến một con số không ít hơn
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              78. Nó có thể được đặt thành
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              79, trong trường hợp đó,
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              04 theo sau bởi
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              03 sẽ luôn được coi là một dòng mới (có thể hợp lý để đọc các tệp có dấu phân cách dòng
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              05). Vỡ nợ.
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              78
            • import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              84 Khoảng thời gian
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              258 sẽ đợi một ký tự (khi đọc một chuỗi khóa mơ hồ tính bằng mili giây, một chuỗi có thể tạo thành một chuỗi khóa hoàn chỉnh bằng cách sử dụng đầu vào đã đọc cho đến nay và có thể nhận thêm đầu vào để hoàn thành một chuỗi khóa dài hơn). Vỡ nợ.
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              86
            • import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              87 Số khoảng trắng của một tab bằng (tối thiểu 1). Vỡ nợ.
              import * as readline from 'node:readline/promises';
              import { stdin as input, stdout as output } from 'node:process';
              
              const rl = readline.createInterface({ input, output });
              
              const answer = await rl.question('What do you think of Node.js? ');
              
              console.log(`Thank you for your valuable feedback: ${answer}`);
              
              rl.close();
              88
            • import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              294 ​​Cho phép đóng giao diện bằng AbortSignal. Hủy bỏ tín hiệu sẽ gọi nội bộ
              ConsoleLine 1
              Line 2
              Line 3
              Line 4
              Line 5
              ...
              225 trên giao diện
          • trả lại.
          • Phương thức

            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            00 tạo một thể hiện
            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            5 mới

            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            26

            Khi phiên bản

            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            5 được tạo, trường hợp phổ biến nhất là lắng nghe sự kiện
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            00

            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            22

            Nếu

            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            49 là
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            218 đối với trường hợp này thì luồng
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            02 sẽ có khả năng tương thích tốt nhất nếu nó xác định thuộc tính
            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            96 và phát ra sự kiện
            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            97 trên
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            02 nếu hoặc khi các cột thay đổi (
            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            99 tự động thực hiện việc này khi là TTY)

            Khi tạo một

            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            5 sử dụng đầu vào là
            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            238, chương trình sẽ không kết thúc cho đến khi nhận được một ký tự EOF. Để thoát mà không đợi người dùng nhập, hãy gọi
            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            239

            Sử dụng hàm
            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            48#

            Hàm

            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            48 lấy dòng hiện tại do người dùng nhập làm đối số và trả về một
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            002 với 2 mục nhập

            • Một
              import { createReadStream } from 'fs'
              import { createInterface } 'readline'
              const readFile = () => { // Step 1
              const rlInterface = createInterface({
              input: createReadStream('app.log'),
              output: process.stdout,
              terminal: false // to indicate this is not TTY
              })
              // Step 2
              rlInterface.on('line', (line) => {
              console.log(line)
              })
              }
              002 với các mục phù hợp để hoàn thành
            • Chuỗi con đã được sử dụng để so khớp

            Ví dụ.

            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            004

            Hàm

            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            48 có thể được gọi không đồng bộ nếu nó chấp nhận hai đối số

            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            28

            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            246#

            Lịch sửPhiên bảnThay đổiv18. 0. 0

            Chuyển một cuộc gọi lại không hợp lệ cho đối số

            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            02 giờ đây ném
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            046 thay vì
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            047

            v12. 7. 0

            Giá trị trả về và gọi lại write() của luồng được hiển thị

            v0. 7. 7

            Đã thêm vào. v0. 7. 7

            Phương thức

            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            250 di chuyển con trỏ đến vị trí đã chỉ định trong TTY
            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            20 đã cho

            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            252#

            Lịch sửPhiên bảnThay đổiv18. 0. 0

            Chuyển một cuộc gọi lại không hợp lệ cho đối số

            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            02 giờ đây ném
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            046 thay vì
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            047

            v12. 7. 0

            Giá trị trả về và gọi lại write() của luồng được hiển thị

            v0. 7. 7

            Đã thêm vào. v0. 7. 7

            Phương thức

            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            256 di chuyển con trỏ so với vị trí hiện tại của nó trong một TTY
            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            20 nhất định

            ConsoleLine 1Line 2Line 3Line 4Line 5...258#

            Phương thức

            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            259 làm cho luồng Có thể đọc đã cho bắt đầu phát ra các sự kiện
            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            260 tương ứng với đầu vào nhận được

            Theo tùy chọn,

            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            261 chỉ định một phiên bản
            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            5 mà tính năng tự động hoàn thành bị tắt khi phát hiện đầu vào đã sao chép

            Nếu

            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            20 là TTY thì nó phải ở chế độ thô

            Điều này được gọi tự động bởi bất kỳ phiên bản readline nào trên

            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            6 của nó nếu
            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            6 là một thiết bị đầu cuối. Việc đóng phiên bản
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            258 không ngăn
            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            6 phát ra các sự kiện
            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            260

            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            29

            Thí dụ. CLI nhỏ #

            Ví dụ sau minh họa việc sử dụng lớp

            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            5 để triển khai giao diện dòng lệnh nhỏ

            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            0

            Thí dụ. Đọc dòng tệp theo từng dòng #

            Một trường hợp sử dụng phổ biến cho

            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            258 là sử dụng một tệp đầu vào mỗi lần một dòng. Cách dễ nhất để làm như vậy là tận dụng API
            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            271 cũng như vòng lặp
            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            264

            Ngoài ra, người ta có thể sử dụng sự kiện

            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            00

            import * as readline from 'node:readline/promises';
            import { stdin as input, stdout as output } from 'node:process';
            
            const rl = readline.createInterface({ input, output });
            
            const answer = await rl.question('What do you think of Node.js? ');
            
            console.log(`Thank you for your valuable feedback: ${answer}`);
            
            rl.close();
            1

            Hiện tại, vòng lặp

            import { createReadStream } from 'fs'
            import { createInterface } 'readline'
            const readFile = () => { // Step 1
            const rlInterface = createInterface({
            input: createReadStream('app.log'),
            output: process.stdout,
            terminal: false // to indicate this is not TTY
            })
            // Step 2
            rlInterface.on('line', (line) => {
            console.log(line)
            })
            }
            264 có thể chậm hơn một chút. Nếu cả tốc độ và tốc độ của
            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            275 /
            ConsoleLine 1
            Line 2
            Line 3
            Line 4
            Line 5
            ...
            276 đều cần thiết, thì có thể áp dụng cách tiếp cận hỗn hợp

            Làm cách nào để đọc từng dòng tệp trong js?

            Trong JavaScript, phương thức tích hợp sẵn FileReader() cùng với mô-đun readline có thể được sử dụng để đọc từng dòng tệp . Phương thức FileReader() đọc nội dung của các tệp được lưu trữ trên hệ thống cục bộ. Hơn nữa, mô-đun readline thực hiện việc đọc nội dung. Cả hai phương pháp này đều yêu cầu nguồn của tệp.

            Làm cách nào để đọc dòng đầu tiên của tệp trong nút js?

            Trong tất cả các phiên bản hiện tại của Node. js, readline. createInterface có thể được sử dụng như một lần lặp không đồng bộ, để đọc từng dòng tệp - hoặc chỉ cho dòng đầu tiên. Điều này cũng an toàn để sử dụng với các tệp trống.

            Làm cách nào để đọc tệp trong nút js?

            Nút. js với tư cách là Máy chủ tệp . var fs = yêu cầu('fs'); . đọc tập tin. use the require() method: var fs = require('fs'); Common use for the File System module: Read files.

            Làm cách nào để đọc 10 dòng cuối cùng của tệp trong nút js?

            createReadStream('của bạn/tệp'); . createInterface(instream, outstream); . on('line', function(line) { // xử lý dòng tại đây }); . on('close', function() { // làm gì đó khi kết thúc tại đây });