I've been working in an example that you can check out here. This example uses Firebase, AngularJs and Azure Functions. I used a bunch of cool tools to create rapidly powerful front-end apps. Today I'll add a couple of new tools like Microsoft Bot Framework and Azure Service Bus to enhance our app in a couple of ways.
The idea is to create a bot that receives a place name and response with the current date and time at that location. After the bot parses the input and generates the proper response, it puts into the Azure Service Bus a message that will trigger our NodeJs Azure Function 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 focus only on our Azure Function. 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 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. Let's dive directly into our function so I can explain to you what's going on. First, I use the method signInAnonymously under the object auth because I need a logged-in user to write in my database. Don't worry — we haven't talked about this yet, but believe me, I'm going to explain to you more about database rules and authentication with Firebase.
Then, I use the object that I receive as a parameter from my Azure Service Bus and directly store it in our database. 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 about the Azure functions, you can use this link. For more details about the NodeJs Azure functions, you can use this link. For mode details about the 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.