title: Node.js: Convert Buffer form USB stream to string
body: <p>I use my Raspberry Pi to read RFID Tags. My RFID Reader is connected by USB, and working like a HID-Keyboard. I use Node.js Version 12.x, an following npm packages:</p>
  <ul>
  <li>node-hid</li>
  <li>usb-detection</li>
  </ul>
  <p>My Code is:</p>
  <pre class="lang-js prettyprint-override"><code>/* app.js */
  const HID = require('node-hid');
  const usbDetect = require('usb-detection');
   
  usbDetect.startMonitoring();
  
  console.log(&quot;=== START ===&quot;)
   
  // Detect add/insert
  usbDetect.on('add', function(device) { 
      console.log('add0', device); 
      listenToInput(device)
  });
   
  // Detect remove
  usbDetect.on('remove', function(device) { console.log('remove0', device); });
  
  
  // Observe input Data
   function listenToInput(device){
      console.log(&quot;Listen start&quot;, device);
      
      // get Connection to RFID Scanner
      var RFIDscanner = new HID.HID(device.vendorId, device.productId);
      RFIDscanner.on(&quot;data&quot;, function(data) {
          console.log(data, new Date())
          
          //var dataArr = Array.prototype.slice.call(new Uint8Array(data, 0, 8))
          //console.log(dataArr);
          //console.log(&quot;string&quot;,data.toString());
          
      });
  }
  
  </code></pre>
  <p>the code works pretty good; I get following output.</p>
  <pre class="lang-js prettyprint-override"><code>&lt;Buffer 00 00 27 00 00 00 00 00&gt; 2019-12-25T17:56:35.692Z
  &lt;Buffer 00 00 00 00 00 00 00 00&gt; 2019-12-25T17:56:35.700Z
  &lt;Buffer 02 00 09 00 00 00 00 00&gt; 2019-12-25T17:56:35.716Z
  &lt;Buffer 00 00 00 00 00 00 00 00&gt; 2019-12-25T17:56:35.724Z
  &lt;Buffer 00 00 27 00 00 00 00 00&gt; 2019-12-25T17:56:35.732Z
  &lt;Buffer 00 00 00 00 00 00 00 00&gt; 2019-12-25T17:56:35.740Z
  &lt;Buffer 00 00 27 00 00 00 00 00&gt; 2019-12-25T17:56:35.756Z
  &lt;Buffer 00 00 00 00 00 00 00 00&gt; 2019-12-25T17:56:35.764Z
  &lt;Buffer 00 00 1e 00 00 00 00 00&gt; 2019-12-25T17:56:35.772Z
  &lt;Buffer 00 00 00 00 00 00 00 00&gt; 2019-12-25T17:56:35.780Z
  &lt;Buffer 02 00 06 00 00 00 00 00&gt; 2019-12-25T17:56:35.796Z
  &lt;Buffer 00 00 00 00 00 00 00 00&gt; 2019-12-25T17:56:35.804Z
  &lt;Buffer 00 00 1e 00 00 00 00 00&gt; 2019-12-25T17:56:35.812Z
  &lt;Buffer 00 00 00 00 00 00 00 00&gt; 2019-12-25T17:56:35.820Z
  &lt;Buffer 00 00 22 00 00 00 00 00&gt; 2019-12-25T17:56:35.836Z
  &lt;Buffer 00 00 00 00 00 00 00 00&gt; 2019-12-25T17:56:35.844Z
  &lt;Buffer 00 00 25 00 00 00 00 00&gt; 2019-12-25T17:56:35.852Z
  &lt;Buffer 00 00 00 00 00 00 00 00&gt; 2019-12-25T17:56:35.860Z
  &lt;Buffer 02 00 04 00 00 00 00 00&gt; 2019-12-25T17:56:35.876Z
  &lt;Buffer 00 00 00 00 00 00 00 00&gt; 2019-12-25T17:56:35.885Z
  &lt;Buffer 00 00 28 00 00 00 00 00&gt; 2019-12-25T17:56:35.892Z
  &lt;Buffer 00 00 00 00 00 00 00 00&gt; 2019-12-25T17:56:35.900Z
  
  </code></pre>
  <h1>My Problem is,</h1>
  <p>how convert the Buffer (-stream?), to String. I tried <code>data.toString()</code>, also with parameters ascii, utf8 and hex; but I don't get the string I want. If I print the RFID Tag in a text file (without my node.js script) I get following output: <code>0F001C158A</code></p>
  <p>Greets</p>