Can't able to read firestore data using firebase functions

Viewed 24

I am trying to get firestore data using firebase functions code ==

const functions = require("firebase-functions");
const admin = require('firebase-admin')
const serviceJson = require('./service.json');
const express = require('express')
const cors = require('cors')
const app = express()
app.use(cors({origin:true}))
admin.initializeApp({
    credential:admin.credential.cert(serviceJson)
})

const db = admin.firestore()

app.get("/", (req,res)=>{
    (async ()=>{
        try{
            const reqDoc = db.collection('users').doc("12345")
            let user = await reqDoc.get();
            let response = user.data()
            return res.status(200).send({status:"Success", data: response})

        } catch(error){
            console.log(error);
            return res.status(500).send({status:"Failed", data: error})
        }
    })();
});

exports.apiFunc = functions.https.onRequest(app)

Getting this error

    +  functions: Loaded functions definitions from source: apiFunc.
i  functions: Beginning execution of "apiFunc"
!  functions: Your function timed out after ~60s. To configure this timeout, see
      https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.
>  C:\Users\Tushar\AppData\Roaming\nvm\v16.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:635
>              throw new Error("Function timed out.");
>              ^
>  
>  Error: Function timed out.
>      at Timeout._onTimeout (C:\Users\Tushar\AppData\Roaming\nvm\v16.16.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:635:19)
>      at listOnTimeout (node:internal/timers:559:17)
>      at processTimers (node:internal/timers:502:7)

Here is firestore data

Got this time out error

please help me to guide what is wrong.

0 Answers
Related