Alon Raskin
Alon Raskin

Reputation: 206

Cloud code: can I use other files besides main.js?

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

Answers (2)

Diogo Andre
Diogo Andre

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

Thomas
Thomas

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

Related Questions