title: How to parse a hex-string to a hex-number from a JSON in node.js
body: <p>I want to save the addresses for an i2c device into a JSON file, but I have no idea how to parse the strings I get back into the addresses in hex notation. </p>
  
  <pre><code>const dev_address = this.parameters['DEVICE_ADDR']; // 0x04
  </code></pre>
  
  <p>First I tried <code>.parseInt(this.parameters['DEVICE_ADDR'], 16)</code>, then I thought the addresses might be some kind of <code>byte[]</code> and tried multiple things using <code>buffer.from(str)</code> and <code>.toString('hex')</code> without success. </p>
  
  <p>How is this done?</p>
  
  <hr>
  
  <p>Reference</p>
  
  <pre><code>'use strict';
  
  const logger = require('../controller/LogController');
  const i2c = require('i2c-bus');
  
  class ArduinoPlug_on {
      constructor(parameters) {
        this.parameters = parameters;
      }
  
      run(env) {
        logger.debug('try connection', this.parameters);
        const dev_address = this.parameters['DEVICE_ADDR']; // 0x04
        const opt_address = this.parameters['OPTION_ADDR']; // 0x00
  
        const i2c1 = i2c.openSync(1);
        const bytesWritten = i2c1.i2cWriteSync(dev_address, 2, Buffer.from([opt_address,0x01]));
        if( bytesWritten == 0 ) {
          logger.error("could not write data", err);
        }
        i2c1.closeSync();
      }
  
      release(env) {
      }
  }
  module.exports = ArduinoPlug_on;
  </code></pre>