Search code examples
node.jsazureweb-applicationspowerbiazure-stream-analytics

Create a nodejs web app that reads data from AZURE. (Stream analytics or Event Hubs or Log analytics)


I have connected several devices to Azure Stream Analytics that will send in various data. ( Temp, light, humidity and etc )

I am not sure how can I read data Azure Resources and display it on my web application that I've published on Azure. For example, reading device_name, device's data.

What I need is probably a sample code that reads some data from Azure and then display it on a simple 'h1' or 'p' tag.

PS: I've seen lots of tutorial that teaches how to publish web app to Azure. But there're hardly any tutorials that specifically teaches how to read and grab data from Azure Resources.


Solution

  • You can use Azure SDK for Node.js to manage Azure resources.

    This is an example retrive information about an existing event hub. And here is the Azure Node SDK reference.

    const msRestAzure = require('ms-rest-azure');
    const EventHubManagement = require('azure-arm-eventhub');
    
    const resourceGroupName = 'testRG';
    const namespaceName = 'testNS';
    const eventHubName = 'testEH';
    const subscriptionId = 'your-subscription-id';
    
    msRestAzure
      .interactiveLogin()
      .then(credentials => {
        const client = new EventHubManagement(credentials, subscriptionId);
        return client.eventHubs.get(resourceGroupName, namespaceName, eventHubName);
      })
      .then(zones => console.dir(zones, { depth: null, colors: true }))
      .catch(err => console.log(err));