Reputation: 206
Does all my cloud clode have to be in main.js or can I create other logical files and somehow add them into my cloud code?
Upvotes: 11
Views: 3633
Reputation: 658
If you just want to split your Parse.Cloud functions in multiple files, you also can do that and just require the file in your main.js.
So you can have this in your cloud/main.js
require('cloud/userFunctions.js')
and have all the related functions in your cloud/userFunctions.js
Parse.Cloud.define("processUserRequest", function(request, response) {
// do your stuff
});
Upvotes: 23
Reputation: 557
You can split your code into different files using require.
The example below come from Parse documentation
If you have some code in cloud/name.js
var coolNames = ['Ralph', 'Skippy', 'Chip', 'Ned', 'Scooter'];
exports.isACoolName = function(name) {
return coolNames.indexOf(name) !== -1;
}
You can then you it in cloud/main.js
var name = require('cloud/name.js');
name.isACoolName('Fred'); // returns false
name.isACoolName('Skippy'); // returns true;
name.coolNames; // undefined.
Upvotes: 8