LeanCloud provides one-stop back-end cloud services, from data storage, real-time chat, message push to mobile statistics, covering various back-end needs of application development.
To use leancloud's cloud functions, you must first be able to use its cloud engine. For nodejs, first create a simple cloud engine project, open the terminal, and type in your local:
npm install -g leancloud-cli
After successful installation, enter:
lean -h
Ask for help.
After that you can create the project:
lean new
Then you follow the prompts of the terminal, step by step (provided that there is an application you have created in your leancloud account). After creation, for example, your project is test. Then open your project in terminal:
cd test
Then install all required dependencies in your project:
npm install
Then pass:
lean up
to start your application.
After that you can open your project, there should be a cloud file in it, there should be only one cloud function in the newly created project, you can add all cloud functions of the project in it. The format of the nodejs cloud function:
AV.Cloud.define('query', function(request, response) {//The first parameter is the name of the function you created var query = new AV.Query ('App'); query.equalTo('app_name', request.params.appname); query.find().then(function(results) { response.success(results); }).catch(function(error) { response.error('query failed'); }); });
After writing, type in the terminal:
lean deploy
Deploy the written cloud function to the cloud engine, and set your own second-level domain name in the cloud engine.
Then call this function on the front end:
var paramsJson = appname: "game" }; AV.Cloud.run('query', paramsJson).then(function(data) { // The call is successful, and the successful response data is obtained }, function(err) { // handle call failure });
Put the front end in the public of the nodejs project and set up your routes. Then open baidu and enter your own second-level domain name to open your own website.