Search code examples
javascriptnode.jsparse-platformparse-cloud-codeparse-server

How does parse cloud code work with parse server?


I am confused after reading Parse's documentation on Cloud Code. They say that Cloud Code is not a Node.js environment.

  • What is the significance to this?
  • Will my request to the server still be handled with the node.js engine ( since the actual server uses Node.js & Express)?
  • How does the cloud code work with the server, are the request going through the server first, than passed to cloud code functions?

E.g when I call a cloud function from the client (In this case a iOS app).

PFCloud.callFunctionInBackground("testCloud", withParameters: [:]) {
            (response: AnyObject?, error: NSError?) -> Void in
            if (error == nil) {
                if let testRespones = response as? String{
                    print(testRespones)
                } 
            } else {
                   print(error)
              } 
}

My parse server is currently hosted on Heroku.

Any insight would be greatly appericated.


Solution

  • Your Cloud Code is literally just a javascript file running in a node.js server instance. When you make a request to the server for your Cloud Code your parse-server express app routes these request, denoted by /cloud, to your file in your cloud directory. In order for this to work you must set your cloud variable in your ParseServer object in index.js. Something like this

    cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js'
    

    So basically when you call a cloud function you're calling the cloud variable in your parse-server which routes you to 'parse-server-directory/cloud/main.js' and finds your function and returns some kind of response.