Mô-đun dòng đọc Node.js

❮ Mô-đun tích hợp


Thí dụ

Mở một tệp và trả lại nội dung từng dòng:

var readline = require('readline');
var fs = require('fs');

var myInterface = readline.createInterface({
  input: fs.createReadStream('demofile1.html')
});

var lineno = 0;
myInterface.on('line', function (line) {
  lineno++;
  console.log('Line number ' + lineno + ': ' + line);
});

Định nghĩa và Cách sử dụng

Mô-đun Readline cung cấp cách đọc một dòng dữ liệu, một dòng tại một thời điểm.


Cú pháp

Cú pháp để bao gồm mô-đun Readline trong ứng dụng của bạn:

var readline = require('readline');

Thuộc tính và phương pháp Readline

Method Description
clearLine() Clears the current line of the specified stream
clearScreenDown() Clears the specified stream from the current cursor down position
createInterface() Creates an Interface object
cursorTo() Moves the cursor to the specified position
emitKeypressEvents() Fires keypress events for the specified stream
moveCursor() Moves the cursor to a new position, relative to the current position

❮ Mô-đun tích hợp