Categories
firebase firebase-admin firebase-realtime-database google-cloud-functions node.js

How do I get the server timestamp in Cloud Functions for Firebase?

I know you can pull the server timestamp in web, ios, and android – but what about the new Cloud Functions for Firebase? I can’t figure out how to get the server timestamp there? Use case is me wanting to timestamp an email when it arrives.

On web it is Firebase.database.ServerValue.TIMESTAMP

But that doesn’t seem to be available in the functions node server interface?

I think it is late and I may be missing the point here…

EDIT

I am initializing like this

admin.initializeApp(functions.config().firebase);
const fb = admin.database()

Then, it is being called like this..

Firebase.database.ServerValue.TIMESTAMP

But, that is from a client side integration. On Functions, Firebase isn’t initialized like this. I’ve tried

admin.database().ServerValue.TIMESTAMP

and

fb.ServerValue.TIMESTAMP

Since you’re already using the admin SDK, the correct syntax is:

admin.database.ServerValue.TIMESTAMP