Node.js Readline- module

❮ Ingebouwde modules


Voorbeeld

Open een bestand en retourneer de inhoud regel voor regel:

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

Definitie en gebruik

De Readline-module biedt een manier om een ​​datastroom regel voor regel te lezen.


Syntaxis

De syntaxis voor het opnemen van de Readline-module in uw applicatie:

var readline = require('readline');

Readline-eigenschappen en -methoden

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

❮ Ingebouwde modules