Node.js रीडलाइन मॉड्यूल
उदाहरण
एक फ़ाइल खोलें और सामग्री लाइन को लाइन से वापस करें:
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);
});
परिभाषा और उपयोग
रीडलाइन मॉड्यूल एक समय में एक डेटास्ट्रीम, एक लाइन को पढ़ने का एक तरीका प्रदान करता है।
वाक्य - विन्यास
आपके आवेदन में रीडलाइन मॉड्यूल को शामिल करने के लिए सिंटैक्स:
var readline = require('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 |