I am trying to initialize the firebase admin sdk in my functions folder so that my cloud function can access my database with admin read/write access, but when I try to deploy my functions the following error is returned
Error: Error parsing triggers: Cannot find module '/serviceKey.json'
I have tried running npm install in the functions directory but it hasn't helped.
Here is my package.json file
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"cors": "^2.8.4",
"express": "^4.16.3",
"firebase": "^5.3.1",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2"
},
"private": true
}
Here is my index.js file
{
const functions = require('firebase-functions');
const express = require('express');
const cors = require('cors')({origin: true});
var firebase = require("firebase");
var admin = require("firebase-admin");
require("firebase/auth");
require("firebase/database");
//require("firebase/firestore");
//require("firebase/messaging");
require("firebase/functions");
var serviceAccount = require("/serviceKey.json");
// Initialize the app with a service account, granting admin
privileges
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://<database name>.firebaseio.com"
});
const displayqr = express();
const geturl = express();
displayqr.get('/displayqr', (request, response) => {
console.log("response sent");
response.send("testio/qrdisplay.html");
});
exports.displayqr = functions.https.onRequest(displayqr);
exports.geturl = functions.https.onCall((email) => {// get url
function
});
}
/serviceKey.json
refers to a file in the root of your file system. That's most likely an error/typo. May be you want./serviceKey.json
? - Hiranya Jayathilakaadmin.initializeApp();
- Hiranya Jayathilaka