title: Generate Connection String For Azure IoT Hub From Device JSON After Creation
body: <p>How do I generate an Azure IoT Hub connection string from <code>deviceInfo</code>, which is a JSON object of device information after I create a new device using the IoT Hub Service NodeJS API.</p>
  
  <p>This is my code snippet below. Inside the callback, where the comment is, I'm trying to get a device connection string to resolve, rather than all the device information.</p>
  
  <pre><code>import iothub from 'azure-iothub';
  const myIoTHub = iothub.Registry.fromConnectionString(...);
  
  function createDevice(device) {
    return new Promise((resolve, reject) =&gt; {
      myIoTHub.create(device, function (err, deviceInfo, res) {
        if (err) reject(err);
        // deviceInfo ---&gt; connectionString
        resolve(connectionString);
      });
    });
  }
  </code></pre>
  
  <p>I reviewed the documentation on Microsoft's website, but the only documentation specifically for connection strings is <a href="https://docs.microsoft.com/en-us/javascript/api/azure-iot-common/ConnectionString?view=azure-node-latest" rel="nofollow noreferrer">this</a>. Here is the <a href="https://docs.microsoft.com/en-us/javascript/api/azure-iothub/device?view=azure-node-latest" rel="nofollow noreferrer">device information</a> object definitions. I know I could parse it myself, but I also couldn't find a specific definition in the documentation on what a connection string consists of. From my experience, I know it's a host name, a device id, and a symmetric key - though I was hoping for an azure function to generate it to isolate myself from issues down the road if the connection string generation changes.</p>
  
  <p><a href="https://www.npmjs.com/package/azure-iothub" rel="nofollow noreferrer">azure-iothub from npm</a></p>
  
  <p>Any assistance would be appreciated.</p>