What’s up guys, Eze is here. I’ve been working in an example that you can check it here, this example uses Firebase, AngularJs and Azure Functions. I used a bunch of cool tools to create rapidly powerful front-end app, in case you missed it you can check here. Today I’ll add couple of new tools like Microsof Bot Framework and Azure Service Bus to enhance our app in a decouple way. The idea is to create a bot that receives a place name and response with the current date time at that location. After the bot parse the input and generate the proper response puts into the Azure Service Bus a message that will trigger our NodeJs Azure Funtion to store the data in Firebase, pretty cool, isn’t it? You can check the working version here.
NodeJs Azure Function
Today we are going to put the focus only in our Azure Function so I’ll talk about how to create a NodeJs Azure function and how to configure it in order to be able to use Firebase from a NodeJs Azure function.
Configuring the environment
Before going further with the explanation of the function I want to explain first how to configure the Azure function to use Firebase node package. Let’s remember that this function is going to run in Azure serverless. That only means that we don’t have full control over our server but we still can run npm install in the function app’s SCM (Kudu) command line interface in order to add packages to our app:
- Navigate to:
- Click Debug Console > CMD.
- Navigate to
npm install firebase --save.
After doing this we will be able to import our Firebase library like this:
var firebase = require('firebase');
After that we can use our firebase object as we did before so let’s dive directly into our function so I can explain you what’s going on. First I use the method signInAnonymously under the object auth and this is because I need a logged in user to write in my database, don’t worry we didn’t talk about it yet but believe me I’m going to explain you more about database rules and authentication with Firebase.
Then I use the object that I receive as parameter from my Azure Service Bus and directly store it in our database. During this week I’ll be posting about the other parts of this system so you can know more about Microsoft Bot Framework and Azure Service Bus
For more details of Azure Functions you can use this link.
For more details of NodeJs Azure Functions you can use this link.
For mode details of Firebase npm package us this link.
If you found this post useful please don’t forget to press the like button and share it. If you are in doubt don’t hesitate to ask a question and as always thank you for reading.