I am trying to use the Parse Javascript SDK in a node.js environment and I am completely baffled as to why I can't get this to work. I use Parse in a Swift iOS application, so I am familiar with Parse client code.
Here's what I'm trying to do:
var Parse = require('parse/node');
function ParseModule() {
var self = this;
self.initialize = function () {
return new Promise(function(resolve, reject) {
Parse.initialize("myAppID", "myJavascriptKey", "myMasterKey");
Parse.serverUrl = "https://myserver.com/parse";
Parse.Cloud.useMasterKey();
var query = new Parse.Query("MyClassName");
query.find()
.then(
function(results) {
console.log("yay! it worked");
resolve();
}
).catch(
function(err) {
output.log("parse error: " + err);
reject(err);
}
);
});
}
return self;
}
module.exports = new ParseModule();
When my module's initialize function is called, after making the 'find' call, in node-debug it just hangs node. In node it just exits the application, so I get no error. This is probably because the wrong (hardcoded) URL to the server is being used.
By the way, I really do want to use the master key not the Javascript key but the initialize method requires the Javascript key.
Also, when I step through the Parse SDK code, I get to this statement:
var url = _CoreManager2['default'].get('SERVER_URL');
in RESTController.js. The server url that it's finding if from the 'config' object which seems to me to be the one used by parse-server. Thus, setting the serverUrl as instructed by the docs has no effect.
Am I not using the correct Parse NPM module? I'm new to node.js.
I'm wasting my entire personal project development day on this!!
Thanks, Peter...
UPDATE: I've added the following line of code after the (almost definitely useless) set of the Parse.serverUrl=... . This seems to fix the issue.
Parse.CoreManager.set('SERVER_URL', "https://myserver.com/parse");
However, this seems like a hack to me. I would appreciate it if someone who is doing something similar to what I'm doing would tell me what I'm doing wrong (i.e. the right way to do this).