3

A brief and clear explanation of how we configure the app.js file and whether we need to require parse-server in it is needed basically. Which files should and shouldn't be related with each other?

For example this is the main.js file where a simple Cloud Code function is defined:

Parse.Cloud.define('hello', function(request, response){
    response.success('Hello world.');
}, function(error){
    response.error(error);
});

So how should the app.js file be configured in order to run that Cloud Code function?

var path = require('path');
var bodyParser = require('body-parser');
var index = require('./routers/index');
app.set('views', path.join(__dirname, '/views'));
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use('/', index);
app.listen();

The above code example of an app.js file doesn't require and has no configuration of parse-server, does it need to?

var express = require('express');
var route = express.Router();
route.get('/', function(req, res){
    Parse.Cloud.run('hello').then(function(r){
        res.send(r);
    }, function(error){
        res.status(400).send(error);
    });
});
module.exports = route;

The above code example of a call in routers/index.js file to a Cloud Code function doesn't work. Is it because the file should require the main.js file or not?

Simple examples of app.js and routers/index.js files will suffice and be deeply appreciated.

nonkertompf
  • 387
  • 1
  • 3
  • 12

1 Answers1

0

Back4App wrote in their Docs that they already configured some lines for us, they're:

‘express’ and ‘app’

//var app = express();

You can take a look at this guide too ;)

For you to know, it is not necessary to call the app.js file in main.js, the app.js is already configured on the Back4App side, but you can edit the routes, for example, in my app, I use a login via Express :)

nataliec
  • 502
  • 4
  • 14