Webhosting – NodeJS web app using Cloud Code

Step 1 – Enable your domain name on Back4app

Contact our support service to enable your domain name.

We will send you the url once the domain name is ready.

The format of the url will like this:  “AppName”.back4app.io

Step 2 – Prepare your express web app Code

In this article, I use the hello world official express web app example.

for more detail about expressjs, go to ExpressJS.

and then upload your code to Cloud Code

Something different on back4app Cloud Code

  1. you don’t need to declare ‘express’ and ‘app’, we prepared for you
  2. placing the public file for public element

screen-shot-2016-10-05-at-6-47-21-pm

 

How to use the Parse Cloud Function with expressJS?

 

app.post('/someFunction', function (req, res) {
 Parse.Cloud.run('someFunction', req.body).then(
 function () {
 console.log('Cloud Code Function called');
 return res.send(200);
 },
 function (error) {
 console.log("CLoud Code Function Called Fail");
 return res.status(400).send(error.message);
 });
});

 

This is the sample code of how to use Parse Cloud Function

you can access it via http://”AppName”.back4app.io/someFunction
You’ll reach http://parseapi.back4app.com/functions/someFunction with your credentials

which is similar to how you test your cloud code with Restful API.

Step 3 – Test it

screen-shot-2016-10-05-at-7-05-58-pm

 

In the server log

screen-shot-2016-10-05-at-7-07-14-pm