I myself created the structure. But it certainly can be improved.
I tried to make my main.js simple. I added only the names of functions that will be called outside of the cloud code.
// Include all of the modules var module1 = require('cloud/folder1/file1.js'); var module2 = require('cloud/folder1/file2.js'); var module3 = require('cloud/folder2/file1.js'); var backgroundjob = require('cloud/backgroundjob/background.js'); Parse.Cloud.job("startBackgroundJob", backgroundjob.startBackgroundJob); Parse.Cloud.define("do_this_stuff", module1.thisfunction); Parse.Cloud.define("do_this_stuff2", module1.notthisfunction); Parse.Cloud.define("do_that_stuff", module2.thatfunction); Parse.Cloud.define("do_dat_stuff", module3.datfunction);
In file1.js, I wrote the following functions.
// Include libraries var utils = require("cloud/utils/utils.js"); var _ = require('underscore'); // Export Modules module.exports = { thisfunction: function (request, response) { addComment(request, response); }, thatfunction: function (request, response) { getComment(request, response); }, }; function addComment(request, response) { // write your code here var stuff = utils.callThisFunction(param); // This is the usage of another function in another file response.success("Comment added"); // or error but do not forget this } function getComment(request, response) { // write your code here response.success("Got Comment"); // or error but do not forget this }
I exported the modules as shown because it makes the code more readable. I can just take a look at the top of the code and see what functions I can use from this file. You can use the document export style .
exports.addComment = function(request, response) {
source share