0

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

2
  • Can you please add the output from the console when you execute the server? Commented Jun 14, 2016 at 14:26
  • Try Post 127.0.0.1:80/webhooks/functions/hello. Commented Jun 15, 2016 at 12:17

2 Answers 2

1

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."}

Sign up to request clarification or add additional context in comments.

Comments

0

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/.

5 Comments

I have ensured that i am running the right script and i tried port 80 as you have suggested. however neither 127... nor localhost:80..etc are returning a result other than "Cannot GET /webhooks/function_hello"
@user3676224, I have updated the instructions to include the port change. If that does not work, please tell me the output of console.log(process.env.PORT).
it has resulted in "undefined", the output is "undefined Cloud Code on Node running on port 80." UPDATE i just want to show you how i placed it " 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);"
Added additional test instructions to answer
Thank you for your help Duane, but it seems parse have changed support status for cloudcode which affects integrating it with NodeJs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.