Sending string over serial to nodejs app. Why does it get chunked? I'm sending a string from my sketch over Serial port as follows:

Serial.println(F("Found ILI9341 LCD driver"));


On the other side, I have a nodejs app using the serialport npm module, with something like this:

var SerialPort = require('serialport')
var serialPort = new SerialPort('/dev/ttyACM1', {
  baudrate: 9600
})

// it opens the connection and register an event 'data'
serialPort.on('open', function () {
  console.log('Communication is on!')
})

// when your app receives data, this event is fired
// so you can capture the data and do what you need
serialPort.on('data', function (data) {
  console.log('data received: ' + data)
})


Communication works, but on nodejs side I get the output chunked, as if it had line breaks, like this:

Communication is on!
data received: Pa
data received: int!
data received: 

data received: Fou
data received: nd I
data received: LI93
data received: 41 L
data received: CD d
data received: rive
data received: r


Why does this happen?
It seems I needed to add a parser to SerialPort nodejs module, in order to specify how the input should be treated. 

I changed my code to this:

var SerialPort = require('serialport')
var Readline = SerialPort.parsers.Readline

var serialPort = new SerialPort('/dev/ttyACM0', {
  baudrate: 9600
})

var parser = new Readline()
serialPort.pipe(parser)
parser.on('data', function (data) {
  console.log('data received: ' + data)
})

serialPort.on('open', function () {
  console.log('Communication is on!')
})


Basically, I'm specifying a Readline parser, which matches with the Serial.println function calls on my arduino sketch. Now the console output works as expected:

Communication is on!
data received: Found ILI9341 LCD driver