Módulo de linha de leitura Node.js

❮ Módulos integrados


Exemplo

Abra um arquivo e retorne o conteúdo linha por linha:

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

Definição e uso

O módulo Readline fornece uma maneira de ler um fluxo de dados, uma linha por vez.


Sintaxe

A sintaxe para incluir o módulo Readline em seu aplicativo:

var readline = require('readline');

Propriedades e métodos de 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ódulos integrados