Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple cloud functions in main.js #3646

Closed
mginz83 opened this issue Mar 16, 2017 · 8 comments
Closed

Multiple cloud functions in main.js #3646

mginz83 opened this issue Mar 16, 2017 · 8 comments

Comments

@mginz83
Copy link

mginz83 commented Mar 16, 2017

I'm confused with having multiple functions in main.js.

If I have multiple cloud functions, I get a bad Jason response error when I run my code. I'm currently developing for Android with my parse server installed locally.

Should I put each function I need in a separate . js file and then include them in main.js???

Thanks

@natanrolnik
Copy link
Contributor

natanrolnik commented Mar 16, 2017

You can have them in separate js files included in main.js, but you don't need to. Check for typos in your current setup.

@mginz83
Copy link
Author

mginz83 commented Mar 16, 2017

I can have multiple main.js? Wouldn't that just overwrite the one? Or having multiple .. js files and use include in the main

@natanrolnik
Copy link
Contributor

natanrolnik commented Mar 16, 2017

You cannot have multiple main.js, but you can have multiple functions in it. As long as they have different names, they don't overwrite each other. I fixed my previous comment.

@mginz83
Copy link
Author

mginz83 commented Mar 16, 2017

Yeah, that strange because I could have sworn I have the stars function in there that comes on the example, as well as a new phone or push notifications, and I got errors. I'll try a different function later. Thanks for this.

@davidju
Copy link

davidju commented Mar 24, 2017

To include other js files in main.js, the code is require("cloud/filename.js"); right? Because when I do this, the cloud code crashes, even if the other js file is empty.

@davidju
Copy link

davidju commented Mar 24, 2017

Never mind, issue is resolved. To include other js files it is supposed to be require("./filename.js");

@Edijae
Copy link

Edijae commented May 18, 2019

@natanrolnik @davidju I have included a file called Common.js that contains cloud code in main.js I have then tried to call this cloud code in another file called Controller.js file but it's not been executed.

Main.js

let common = require('./Common');
 let controller = require('./Controller');

Controller.js

Parse.Cloud.define("save", async (request) => {
 // other logics here
var params = {"id":"ABCDEF"}
 const result = await Parse.Cloud.run("Update", params);
        console.log("updated summary?+++++++++++++++++++++++++++++++++++++++++++" + result)
})

Common.js

Parse.Cloud.define("Update", async (request) => {
 console.log("Update function called------------")
return true
});

console.log("Update function called------------") is not being executed at all

@Skyb0rg
Copy link

Skyb0rg commented Dec 9, 2020

ave included a file called Common.js that contains cloud code in main.js I have then tried to call this cloud code in another file called Controller.js file but it's not been executed.

your Main.js should only include the other files like:

 require("./Controller.js");
 require("./Common.js");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants