title: Writing and reading data between two nodejs servers using node serial port
body: <p>I would like to send &quot;Hello world&quot; from one nodejs server to another using node-serialport.  I have verified that the radios connecting the two are connected and sending info because they keep displaying buffer information after running my current code.<br />
  here is what I have so far.</p>
  <p>server1</p>
  <pre><code>// Import dependencies
  const SerialPort = require(&quot;serialport&quot;);
  const Readline = require(&quot;@serialport/parser-readline&quot;);
  
  var sf = require('sf');
  
  //SerialPort.list(function (err, results) {
  //  if (err) {
  //    throw err;
  //  }
  
    SerialPort.list().then(ports =&gt; {
      ports.forEach(function(port) {
        console.log(port.path);
        console.log(port.pnpId);
        console.log(port.manufacturer);
      });
    });
  
  
  // Defining the serial port
  const port = new SerialPort('COM3',{baudRate: 9600}, function (err) {
    if (err) {
      return console.log('Port Error: ', err.message)
    }
  })
  
  port.write('main screen turn on', function(err) {
    if (err) {
      return console.log('Error on write: ', err.message)
    }
    console.log('message written')
  })
  
  // Read data that is available but keep the stream in &quot;paused mode&quot;
  port.on('readable', function () {
    console.log('Data:', port.read())
  })
  
  // Switches the port into &quot;flowing mode&quot;
  port.on('data', function (data) {
    console.log('Data:', data)
  })
  
  // Pipe the data into another stream (like a parser or standard out)
  const lineStream = port.pipe(new Readline())
  
  lineStream.on('data', console.log)
  </code></pre>
  <p>server 2</p>
  <pre><code>// Import dependencies
  // in Ubuntu need to run command: sudo chmod 666 /dev/ttyS0 to open port for use
  const SerialPort = require(&quot;serialport&quot;);
  const Readline = require(&quot;@serialport/parser-readline&quot;);
  
  var stoploop = true;
  
  // Defining the serial port
  const port = new SerialPort('/dev/ttyUSB0', function (err) {
    if (err) {
      return console.log('Error: ', err.message)
    }
  })
  
  
  port.write('chicken butt', function(err) {
      if (err) {
          return console.log('Error on write: ', err.message)
      }
      console.log('message written')
  })
  
  // port.write(&quot;hello?&quot;);
  // Read data that is available but keep the stream in &quot;paused mode&quot;
  port.on('readable', function () {
    console.log('Data:', port.read())
  })
  
  // Switches the port into &quot;flowing mode&quot;
  port.on('data', function (data) {
    console.log('Data:', data)
  })
  
  // Pipe the data into another stream (like a parser or standard out)
  const lineStream = port.pipe(new Readline())
  
  </code></pre>
  <p>any help or even an example of how to send hello world between the two would be greatly appreciated! please let me know if any more info is needed.</p>
  <p>edit : I recently tried doing something like</p>
  <pre><code>port.on('data', (data) =&gt; {
    try {
      console.log(data.toString());
    } catch (err) {
      console.log('Oops');
    }
  });
  </code></pre>
  <p>this is taking data that used to appear as &lt;buffer # # # # #&gt; and turning it into an odd string like &quot;(
  ))))    ) )      )))
  !)☺)!)))        )  )
  )(☺!�&quot;</p>