I am new to firebase function and trying to use firebase function with Realtime database (Emulator suite).But when i try to set the value in firebase using the firebase function,it gives an error and doesn't set the value in database.
Error:
17:33:14
I
function[us-central1-textToLength]
[2021-11-05T12:03:14.194Z] @firebase/database: FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets. Trying anyway.
17:34:18
I
function[us-central1-textToLength]
[2021-11-05T12:04:18.762Z] @firebase/database: FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets. Trying anyway.
17:35:06
I
function[us-central1-textToLength]
[2021-11-05T12:05:06.473Z] @firebase/database: FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets. Trying anyway.
17:35:54
I
function[us-central1-textToLength]
[2021-11-05T12:05:54.409Z] @firebase/database: FIREBASE WARNING: wss:// URL used, but browser isn't known to support websockets. Trying anyway.
firebase function code :
const functions = require('firebase-functions');
var admin = require("firebase-admin");
admin.initializeApp();
var database = admin.database();
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
exports.textToLength = functions.https.onRequest((request, response) => {
var tex = request.query.text;
var textLength = tex.length;
console.log(textLength);
database.ref().child('test').set("op");
response.send(String(textLength));
});
dependencies :
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "14"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1",
"@firebase/database-compat": "0.1.2"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}
npm installed packages
+-- @firebase/[email protected]
| +-- @firebase/[email protected]
| | +-- @firebase/[email protected]
| | | +-- @firebase/[email protected] deduped
| | | `-- [email protected] deduped
| | +-- @firebase/[email protected]
| | | `-- [email protected] deduped
| | +-- @firebase/[email protected]
| | | `-- [email protected] deduped
| | `-- [email protected] deduped
| +-- @firebase/[email protected]
| | +-- @firebase/[email protected] deduped
| | `-- [email protected] deduped
| +-- @firebase/[email protected]
| | `-- [email protected] deduped
| +-- @firebase/[email protected]
| | `-- [email protected] deduped
| `-- [email protected]
+-- @firebase/[email protected]
| +-- @firebase/[email protected]
| | +-- @firebase/[email protected] deduped
| | `-- [email protected] deduped
| +-- @firebase/[email protected]
| | +-- @firebase/[email protected]
| | +-- @firebase/[email protected] deduped
| | +-- @firebase/[email protected] deduped
| | +-- @firebase/[email protected] deduped
| | +-- [email protected]
| | | `-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected] deduped
| | | `-- [email protected]
| | `-- [email protected] deduped
| +-- @firebase/[email protected]
| | +-- @firebase/[email protected]
| | `-- @firebase/[email protected] deduped
| +-- @firebase/[email protected]
| | `-- [email protected] deduped
| +-- @firebase/[email protected]
| | `-- [email protected] deduped
| `-- [email protected] deduped
`-- [email protected]
+-- @firebase/[email protected] deduped
+-- @firebase/[email protected]
| `-- @firebase/[email protected]
+-- @google-cloud/[email protected]
| +-- [email protected]
| +-- [email protected]
| +-- [email protected]
You can use both Firebase Realtime Database and Cloud Firestore in your app, and leverage each database solution's benefits to fit your needs. For example, you might want to leverage Realtime Database's support for presence, as outlined in Build Presence in Cloud Firestore.
256 MB from the REST API; 16 MB from the SDKs. The total data in each write operation should be less than 256 MB.
The Firebase Realtime Database can be accessed directly from a mobile device or web browser; there's no need for an application server. Security and data validation are available through the Firebase Realtime Database Security Rules, expression-based rules that are executed when data is read or written.
In the meantime, if you are on the latest Admin SDK version, you can pin @firebase/database-compat to version 0.1.2 in your package.json file as a temporary fix.
"dependencies": { "@firebase/database-compat": "0.1.2" }
This works for me.
Ref: https://github.com/firebase/firebase-admin-node/issues/1487
In the meantime, if you are on the latest Admin SDK version, you can pin @firebase/database-compat to version 0.1.2 in your package.json file as a temporary fix.
"dependencies": { "@firebase/database-compat": "0.1.2" }
This works for me.
Ref: https://github.com/firebase/firebase-admin-node/issues/1487
I referred this example and it worked but for this to work rebuild your package-lock.json file by removing node_modules folder and package_lock.json file and running npm install --package-lock-only
Yes, definitely known issue currently they are working on a fix like Kasirajan suggested https://github.com/firebase/firebase-admin-node/issues/1487#issuecomment-962219551. This fix worked for us. Wanted to upvote his comment but my reputation is still low haha but I can verify that works.
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