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

Justin Handley picture Justin Handley · Apr 23, 2017 · Viewed 35.9k times · Source

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

Answer

Frank van Puffelen picture Frank van Puffelen · Apr 24, 2017

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

admin.database.ServerValue.TIMESTAMP