Note that there are some explanatory texts on larger screens.

plurals
  1. PONodejs and TypeError method 'trim' undefined when processing data from streaming
    text
    copied!<p>i have data below from streaming:</p> <pre><code>'ID|20120206|080500|0000001|0|1|record1|END' 'ID|20120206|080500|0000002|0|1|record2|END' 'ID|20120206|080500|0000003|0|1|record3|END' </code></pre> <p>and i want to process the streaming data line by line using nodejs code below:</p> <pre><code>var net = require('net'); var HOST = 'localhost', PORT = 9010, lastSeqNo = 0; var client = new net.Socket(); client.setEncoding('ascii'); client.connect(PORT, HOST, function () { console.log('Connected to: %s : %d', HOST, PORT); }); client.on('close', function (hadError) { console.log(hadError); }); client.on('error', function (ex) { console.log(ex); }); var i = 1; var Line = function (rows, data) { this.SeqNo = parseFloat(rows[3].trim()); this.Date = rows[1].trim(); this.Time = rows[2].trim(); this.MsgType = parseInt(rows[4].trim(), 10); this.Data = data; }; client.on('data', function (data) { var content = data.split('\r\n'); content.forEach(function (item) { if (item.length &gt; 0) { console.log(i, item); i++; var rows = item.split('|'), line = new Line(rows, data), seqNo = line.SeqNo, msgType = line.MsgType; console.log('seqno:', seqNo); } }); }); </code></pre> <p>after a few data line process, i got some error like below:</p> <pre><code>D:\test node\app.js:33 this.SeqNo = parseFloat(rows[3].trim()); ^ TypeError: Cannot call method 'trim' of undefined at new &lt;anonymous&gt; (D:\test node\app.js:33:37) at D:\test node\app.js:48:24 at Array.forEach (native) at Socket.&lt;anonymous&gt; (D:\test node\app.js:42:13) at Socket.emit (events.js:67:17) at TCP.onread (net.js:362:31) </code></pre> <p>could you help me what's wrong with my code above?</p> <p>thank you. greeting from indonesia.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload