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

Calling a Function in Index.js from Cloud Function #4531

Closed
skparticles opened this issue Jan 30, 2018 · 3 comments
Closed

Calling a Function in Index.js from Cloud Function #4531

skparticles opened this issue Jan 30, 2018 · 3 comments

Comments

@skparticles
Copy link

skparticles commented Jan 30, 2018

I know how to call a function and pass values from index.js to Cloud Code

How to do this in reverse side? Calling a function in Index.js from a Cloud function.

index.js

//Parse Server Initialization
var api = new ParseServer({
    databaseURI: databaseUri,
......
});

function call_this_function_from_cloud_code(req ,res){
}

cloud/main.js

function cloud_function_to_call(){
   //How to call 
   //call_this_function_from_cloud_code
}
@tolgaatam
Copy link

in index.js , export your function and in your cloud code javascript file, you can import the function derived from the index page. There are several syntaxes for exporting and importing, use the es6 way id you are using nodejs 6xx + :

index.js:

export function call_this_function_from_cloud_code(req, res){}

cloud/main.js

import { call_this_function_from_cloud_code } from “../index”;

...

@skparticles
Copy link
Author

@tolgaatam I am not clear, any simple code snippets?

@skparticles
Copy link
Author

index.js

//Parse Server Initialization
var api = new ParseServer({
    databaseURI: databaseUri,
......
});

Parse.Cloud.define("sendToChat", function (req, res) {
console.log("It is called in the index.js");
});

cloud/main.js

Parse.Cloud.run('sendToChat', {}).then(function (ratings) {
// ratings should be 4.5
});

Parse is globally defined you should be able to use Parse Queries and Parse.Cloud in your index.js. Thanks @dplewis

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

2 participants