Advertisement
Guest User

Background Cloud Function example

a guest
Jul 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Background Cloud Function to be triggered by Pub/Sub.
  3.  * This function is exported by index.js, and executed when
  4.  * the trigger topic receives a message.
  5.  *
  6.  * @param {object} event The Cloud Functions event.
  7.  * @param {function} callback The callback function.
  8.  */
  9. exports.helloPubSub = (event, callback) => {
  10.   const pubsubMessage = event.data;
  11.   const name = pubsubMessage.data ? Buffer.from(pubsubMessage.data, 'base64').toString() : 'World';
  12.  
  13.   console.log(`Hello, ${name}!`);
  14.  
  15.   callback(1);
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement