user3676224
user3676224

Reputation: 873

parse-Server cloudCode with nodejs

I am using parse-server and I want to use nodejs with cloudCode as in the example below.

This is the example: Adding nodejs to Parse

here is the example code from the link

    var http = require('http');
var express = require('express');
var bodyParser = require('body-parser');
var ParseCloud = require('parse-cloud-express');
var Parse = ParseCloud.Parse;
var app = express();
// Host static files from public/
app.use(express.static(__dirname + '/public'));
// Define a Cloud Code function:
Parse.Cloud.define('hello', function(req, res) {
  res.success('Hello from Cloud Code on Node.');
});
// Mount the Cloud Code routes on the main Express app at /webhooks/
// The cloud function above will be available at /webhooks/function_hello
app.use('/webhooks', ParseCloud.app);
// Launch the HTTP server
var port = process.env.PORT || 80;
var server = http.createServer(app);
server.listen(port, function() {
  console.log('Cloud Code on Node running on port ' + port + '.');
});

console.log(process.env.PORT);

I have imported all the required modules, but still, when I run the server and try to go to the link "127.0.0.1/webhooks/function_hello" I get back Cannot GET /webhooks/function_hello

Any advise?

*OUTPUT when i run the script *

    undefined
Cloud Code on Node running on port 80.

UPDATE it seems that with parse's shutdown that they have changed support status for cloudcode which affects integrating it with NodeJs

Upvotes: 0

Views: 475

Answers (2)

Egor Litvinchuk
Egor Litvinchuk

Reputation: 1870

Had the same issue. GET doesn't work here. You need to make a POST request, and then you'll get {"success":"Hello from Cloud Code on Node."}

Upvotes: 1

Duane
Duane

Reputation: 4499

Please make sure you are running the right script with node SCRIPT_NAME

It appears your express server is set to port 5000.

See: var port = process.env.PORT || 5000;

Change your URL to http://127.0.0.1:5000/webhooks/function_hello or localhost:5000/webhooks/function_hello and it should appear

If you want to run on the default port (80) you will need to run with sudo for your script and make the following change to the code.

var port = process.env.PORT || 80;

Add a folder to your directory named public. Inside that folder place a file named index.html. Type Hello World in that file, save it. Restart your server. See if you can open http://127.0.0.1/.

Upvotes: 0

Related Questions