Deploy Firebase Functions

Note:

This section has to be considered if you have purchased code that contains a “Firebase” or “FirebaseFunctions” folder inside.

All the necessary Firebase Functions have been initially coded by us, you just need to deploy these functions to your own Firebase account. This means that you need to upload the source code inside the FirebaseFunctions folder to your account. If a Firebase account has been created, find a Firebase project, and 2 apps (iOS and Android).

Follow these steps for setup
Step 1: Setting up Node.js and the Firebase CLI
  • Use the official Firebase doc if you encounter any issues.
  • Node.js and Firebase CLI is needed to write functions and deploy them to the Cloud Functions. Install Node.js and npmNode Version Manager. After Node.js and npm are installed, install the Firebase CLI. Use: npm install -g firebase-tools, to install the CLI via npm.
Step 2: Initialize your project

An empty project containing sample code is created when you initialized Firebase SDK for cloud functions.

For initializing the project:

  • Authenticate the firebase tool by running the firebase login via browser
  • You need to create a new “MyFirebaseFunctions” empty folder
  • Go to the MyFirebaseFunctions project directory and run firebase init functions
  • With the tool, you can install npm. Before emulating or deploying your functions, you’ll need to run npm install
  • The tool gives you two options for language support:
    • – JavaScript
    • – TypeScript
  • Please select JavaScript.

During initialization, package.json file is created that contains an important key: “engines”: {“node”: “12”}. Make sure it is Node.js version 12, before writing and deploying functions.

Step 3: Adding Foodie Functions

As we are providing the full source code for your Firebase Functions, all you need to do is add that source code into your newly created MyFirebaseFunctions project. Follow these steps to proceed:

  • – In the Foodie’s FirebaseFunctions folder, copy the “functions” subfolder to the clipboard.
  • – Paste it to MyFirebaseFunctions folder, and OVERRIDE the functions folder. Now you have a Firebase Functions project, that is linked to your Firebase account with our source code that works on the mobile app
Step 4: Deploy Firebase Functions

To deploy Firebase Functions, you need to make sure you upgrade your Firebase Pricing Plan to Blaze.

Simply run the command (firebase deploy –only functions) in the project directory

Now you can go to your Firebase Console and check, as the functions have been deployed. It is possible to see the logs for each function, understand the output, and know when it gets called.

Step 5: Watch Firebase Functions for Errors

To run properly, some Firebase functions need the creation of indexes on certain Firestore collections. Use the app and watch the logs for the Firebase Functions in the console. If you happen to get an error of missing index, simply click on the URL of that error, and the index will get created automatically. There is no need to deploy functions again, but wait until the index is created, before testing the app again.