skip to Main Content

I am created a firebase function which shown in below, but i don’t how to debug it i am serving this with npm run serve

I am trying to creating, updating, deleting data in my real time database, if you see the reference is giving is development. but when i checking my rt DB it doesn’t change anything.
first i am editing my textEdit field after i see it doesn’t update anything.

export const tri= functions.database.ref('/development').onWrite((change, context) => {
      //
      functions.logger.log("dddd", change, context)
      console.log("logggg", change.after.val())

      return change.after.ref.update({ textEdit: new Date() })
})                                                                                 

console.log("1")

2

Answers


  1. Don’t use npm run serve use firebase serve to test and debug functions locally.

    Login or Signup to reply.
  2. You can use firebase emulators:start, emulators:start will start the emulator for your functions which allows you to test and debug your Functions locally,You can test your functions in this way before putting them into the production environment. You can interact with the functions in the same way you would when they were deployed once the emulators are running, which can help you quickly find and fix bugs and errors.you can check this document1 which is shared in above comment and also this document2 for more information

    To initialize Firebase Emulators locally

    • Install the Firebase CLI. If you don’t already have the Firebase CLI installed, install it now.

    • Initialize the current working directory as a Firebase project.

      firebase init
      
    • Initialize Firebase emulators on local development machine.

      firebase init emulators                                            
      
    • To run the Cloud Functions emulator, use the emulators:start command:

      firebase emulators:start
      
    • The emulators:start command will start emulators for Cloud Functions, Cloud Firestore, Realtime Database, and Firebase Hosting
      based on the products you have initialized in your local project using
      firebase init. If you want to start a particular emulator, use the
      –only flag:

      firebase emulators:start --only functions
      
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search