After creating a cloud function addMessage
on Firebase using Firebase SDK 4.12.0, the following code does not work when attempting to call the addMessage
function from within my client app:
var firebase = require("../node_modules/firebase")
var functions = firebase.functions();
functions.httpsCallable("addMessage").call(
//...
)
TypeError: firebase.functions is not a function
Cloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your JavaScript or TypeScript code is stored in Google's cloud and runs in a managed environment.
Cloud Functions includes a perpetual free tier for invocations to allow you to experiment with the platform at no charge. Note that even for free tier usage, we require a valid billing account.
There are two types of Cloud Functions: HTTP functions, which handle HTTP requests and use HTTP triggers. See Write HTTP functions for information about implementing HTTP functions. Event-driven functions, which handle events from your cloud environment and use event triggers as described in Cloud Functions triggers.
The Cloud Functions for Firebase client SDKs let you call functions directly from a Firebase app. To call a function from your app in this way, write and deploy an HTTPS Callable function in Cloud Functions, and then add client logic to call the function from your app.
The solution was to add
require("firebase/functions")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With