Azure Functions : Extending the “quick demo” from earlier this week


Last week we did a quick demo on Azure Functions in combination with the event hub. Today I wanted to explore what would happen if I wanted to use “custom” libraries. Could I install libraries on functions? Let’s try it out shall we!


Install NPM Module in 

First thing we’ll do is install the extra npm module we need. We can do this via the “kudu“-console ;


Just like we would anywhere else…


Adding an extra output

As I want to output the csv files to another container, I’ll be adding an additional output ;


Same like before…


The Function!

Now let’s extend the function…


module.exports = function (context, myEventHubTrigger) {
    context.log('JavaScript eventhub trigger function processed work item', myEventHubTrigger);
    context.bindings.outputBlob = myEventHubTrigger;

    var json2csv = require('json2csv');
    var fields = ['Temperature', 'Pressure'];
    context.bindings.outputBlobby = json2csv({ data: myEventHubTrigger, fields: fields });


We’ve added the necessary code to convert the json 2 csv and send it to our new output.


Test driving it

So we have our little test script…


Which I’ll be running every 10 seconds ; 2016-12-06-17_10_05-program-manager

And great, that’s doing its thing…2016-12-06-17_10_21-kvaessw10kavs_-_xca_functions

The function receives & processes the messages ;
Where the new output receives files.

Which contains csv files!

Based upon the json from the other container.



So it works! 😀

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.