我正在嘗試創建一個節點應用程序,它使用'readline'模塊逐行讀取文本文件,並將其打印到控制檯。節點readline模塊沒有'on'功能?
var lineReader = require('readline');
lineReader.createInterface({
input: fs.createReadStream('./testfile')
});
lineReader.on('line', function(line){
console.log(line);
});
根據該模塊的文檔,there should be an 'on' method。然而,當我登錄我創建readline的對象的實例,我沒有看到一個「上」的方法在任何地方:
{ createInterface: [Function], Interface: { [Function: Interface]
super_:
{ [Function: EventEmitter]
EventEmitter: [Circular],
usingDomains: false,
defaultMaxListeners: [Getter/Setter],
init: [Function],
listenerCount: [Function] } },
emitKeypressEvents: [Function: emitKeypressEvents],
cursorTo: [Function: cursorTo],
moveCursor: [Function: moveCursor],
clearLine: [Function: clearLine],
clearScreenDown: [Function: clearScreenDown],
codePointAt: [Function: deprecated],
getStringWidth: [Function: deprecated],
isFullWidthCodePoint: [Function: deprecated],
stripVTControlCharacters: [Function: deprecated] }
所以,自然,當我打電話lineReader.on(),我得到一個錯誤稱該功能不存在。
我正在關注文檔......我錯過了什麼? on方法在哪裏?
非常感謝你的時間。
謝謝澄清 – SemperCallide