Call external function from cloud code async? (syntax)


Hey guys,

I have a simple (I guess) question - How can I call an external function from Cloud.define?

Parse.Cloud.define("testCall", async (request) => {
// do something

For a better structure I like to cluster my functions over some “lib” files. But I don’t know how to call them directly in this via syntax.

Parse.Cloud.define("testCall", async (request) => lib.function1 );

(Not working)

Anyone can help? =)


cloud function is a nodejs file so for accessing other files you should import it using require
for example in following file structure your testCall.js cloud code file would be like this;

var util = require('./lib/util');
Parse.Cloud.define("testCall", async (request) => {

And in util.js you should export your functions like this:

exports.someFunction = function(text) {
    // Do something

Folder structure:

   util.js  <-- utility js file containing helper functions
1 Like


found the answer.

async function fetchSomething(){
// Do something
exports.fetchSomething = fetchSomething;

and in functions.js

var util = require('./lib/util');
Parse.Cloud.define("testCall", util.fetchSomething);


1 Like