I am reading data from the serial port using Node JS (which I am quite new to at the moment). Although I can see the data through an stdout stream via console.log and get a static value on the webpage I cannot get the value to update on a continuous basis. My current code looks like this:
var http = require('http');
const SerialPort = require('serialport');
const Readline = require('@serialport/parser-readline');
const port = new SerialPort('/dev/ttyACM0', { baudRate: 9600 });
const parser = port.pipe(new Readline({ delimiter: '\r\n' }));
http.createServer(function (request, response) {
parser.on('data', (data) => {
console.log(data);
response.writeHead(200, {"Content-Type":"text/html"});
response.write(data);
});
}).listen(8888);
Is there a way I can get the serial data to update in realtime on the webpage as opposed to having to refresh the page?
Node JS version: v12.18.2