Scorocode.CloudCode
Class for handling server-side scripts
Contents:
- .CloudCode
- new CloudCode(id)
- .run(pool, callbacks) ⇒
promise.{error: Boolean}
new CloudCode(id)
Creates a new subclass of Scorocode.CloudCode() for the given script identifier
Returns: Scorocode.CloudCode
- Returns new Scorocode.CloudCode instance
Parameter | Type | Description |
---|---|---|
id | String |
Server-side script identifier |
logger | Object |
Logger object for debugging |
.run(pool, debug, callbacks)
Server code running method
Parameter | Type | Description |
---|---|---|
pool | Object |
Object with the data that will be passed to the server-side script |
debug | Boolean |
Flag for debug mode |
callbacks | Object |
Success and error callbacks for the executed query |
Example
// Подключим SDK и инициализируем его.
var Scorocode = require('scorocode');
Scorocode.Init({
ApplicationID: "applicationId",
JavaScriptKey: "javascriptKey",
ScriptKey: "scriptKey"
});
var Prompt = require('prompt');
Prompt.start();
Prompt.get(['email', 'password', 'username'], function (err, result) {
var newUserRegistration = new Scorocode.CloudCode("574860d2781267d34f7a2415");
var pool = {
"email":result.email,
"password":result.password,
"username":result.username
};
newUserRegistration.run(pool)
.then((success)=>{
console.log(success);
})
.catch((error)=>{
console.log(error)
});
});
Returns: promise.{error: Boolean}
- Returns promise that returns object
{
error: false
}
Exceptions:
String
'Invalid type of pool'
Debug
When you use JavaScript SDK it can be possible to debug server-side scripts. To access debug mode you need to initialise sdk Scorocode.Init({})
with MasterKey and WebsocketKey.
You need to create Logger
object to activate debug mode.
Example
var Scorocode = require('scorocode');
Scorocode.Init({
ApplicationID: "applicationId",
JavaScriptKey: "javascriptKey",
ScriptKey: "scriptKey"
MasterKey: "masterKey" // necessary for debug
WebSocketKey: "websocketKey" // necessary for debug
});
var Prompt = require('prompt');
Prompt.start();
Prompt.get(['email', 'password', 'username'], function (err, result) {
var newUserRegistration = new Scorocode.CloudCode("574860d2781267d34f7a2415", {logger: new Scorocode.Logger()});
var pool = {
"email":result.email,
"password":result.password,
"username":result.username
};
newUserRegistration.run(pool, true)
.then((success)=>{
console.log(success);
})
.catch((error)=>{
console.log(error)
});
});