coure2011
coure2011

Reputation: 42504

Running a firebase trigger event locally

I have a simple method like

exports.updatePlayer = functions.firestore
  .document('matches/{docId}')
  .onCreate((change, context) => {
    console.log('fired------------', context.params.docId);
  });

If I add a new doc to matches, I can see the console message in logs.

Question is how I can run it locally? I have this cmd in package.json

"serve": "firebase emulators:start --only functions,database",

When I run `npm run server', console says

> functions@ serve D:\cric\fs-functions\functions
> firebase emulators:start --only functions,database

i  emulators: Starting emulators: functions
!  database: Not starting the database emulator, make sure you have run firebase init.
+  hub: emulator hub started at http://localhost:4400
!  Your requested "node" version "8" doesn't match your global version "12"
+  functions: functions emulator started at http://localhost:5001
i  functions: Watching "D:\cric\fs-functions\functions" for Cloud Functions...
!  functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
+  functions[allMatches]: http function initialized (http://localhost:5001/xxxx-xxxxx/us-central1/allMatches).
i  functions[updatePlayer]: function ignored because the firestore emulator does not exist or is not running.
+  emulators: All emulators started, it is now safe to connect.

But now if I add something to firestore collection, I am not getting any console message on my local terminal. Also not that i functions[updatePlayer]: function ignored because the firestore emulator does not exist or is not running.

I want to run this trigger locally, so can write/test my code fast.

Upvotes: 0

Views: 603

Answers (1)

v1gnus
v1gnus

Reputation: 311

Try to update your NodeJs version

Firebase announced the deprecation of Node.js 8 runtime on Cloud Functions and the decommissioning of the Node.js 6 runtime.

To ensure that your functions are on a supported version of Node.js, migrate to the Node.js 10 runtime as soon as possible.

Update from Node.js 8 to Node.js 10 specifying the Node.js 10 runtime explicitly by setting the engines field in package.json

NodeJs End-of-Life Releases

Upvotes: 1

Related Questions