NodeJS: Parse Cloud Example


/ Published in: JavaScript
Save to your folder(s)

Parse Cloud Code allows you to build an ExpressJS app that connects with Parse's specialized cloud functions + infrastructure. These two examples simply show how you can access Parse's methods: through webhooks or cloud calls.


Copy this code and paste it in your HTML
  1. /**** **** **** **** **** **** **** ****
  2. Two examples of how to Run Parse.Cloud
  3. code with Express
  4. **** **** **** **** **** **** **** ****/
  5. /*
  6. Example: Cloud Function Call
  7. You Can seperate the Parse specific logic from your app
  8. by using CloudFunctions. It keeps seperation nice and tidy.
  9. */
  10. function runParseCode(formData, callback){
  11. Parse.Cloud.run('hello', formData, {
  12. success: function(results) {
  13. callback(true)
  14. },
  15. error: function(results, error) {
  16. callback(false, error)
  17. }
  18. });
  19. }
  20. function example1(){
  21. runParseCode(formData, function(boolean, error){
  22. if(boolean) res.render('thankyou')
  23. else res.send({"message": "error", "error": error)
  24. });
  25. }
  26. //example1()
  27.  
  28. /*
  29. Example: Custom Webhook
  30. Since all of this is in the cloud,
  31. ExpressJS has full access to Parse
  32. */
  33. function runWebHook(formData, callback){
  34. var TestObject = Parse.Object.extend("TestObject");
  35. var testObject = new TestObject();
  36. testObject.save( formData, {
  37. success: function(results) {
  38. callback(true)
  39. },
  40. error: function(results, error) {
  41. callback(false)
  42. }
  43. });
  44. }
  45. function example2(){
  46. var data = {
  47. "fname":"chris",
  48. "lname":"aiv",
  49. "username":"chrisaiv0.29115835297852755",
  50. "password":"password",
  51. "email":"[email protected]",
  52. "phone":"555-555-5555"
  53. }
  54. runWebHook(data, function(boolean){
  55. if(boolean) res.render('thankyou');
  56. else res.send({"message": "error", "error": error)
  57. })
  58. }
  59. //example2()

URL: https://www.parse.com/docs/cloud_code_guide

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.