Skip to content
Merged
34 changes: 34 additions & 0 deletions functions/node8/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,37 @@ exports.helloAnalytics = (data, context) => {
console.log(`Location: ${userObj.geoInfo.city}, ${userObj.geoInfo.country}`);
};
// [END functions_firebase_analytics_node8]

// [START functions_background_promise_node8]
/**
* Background Cloud Function that returns a Promise. Note that we don't pass
* a "callback" argument to the function.
*
* @param {object} data The Cloud Functions event data.
* @returns {Promise}
*/
exports.helloPromise = (data) => {
const request = require('request-promise');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this outside of the function, and use two region tag blocks? e.g:

// [START tag_name]
const library = require('library');
// [END tag_name]

...

// [START tag_name]
exports.useLibrary = () => {
  ...
}
// [END tag_name]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I copied this from the original Node 6 sample though: https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/master/functions/background/index.js#L47-L53

Should that one be changed as well?


return request({
uri: data.endpoint
});
};
// [END functions_background_promise_node8]

// [START functions_background_synchronous_node8]
/**
* Background Cloud Function that returns synchronously. Note that we don't pass
* a "callback" argument to the function.
*
* @param {object} data The Cloud Functions event data.
*/
exports.helloSynchronous = (data) => {
// This function returns synchronously
if (data.something === true) {
return 'Something is true!';
} else {
throw new Error('Something was not true!');
}
};
// [END functions_background_synchronous_node8]
4 changes: 4 additions & 0 deletions functions/node8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@
"ava": "^0.25.0",
"semistandard": "^12.0.1",
"uuid": "^3.3.2"
},
"dependencies": {
"request": "^2.88.0",
"request-promise": "^4.2.2"
}
}