The Backendless API for JavaScript can be used not only from the browser-based JavaScript applications but also from a Node.js program. Using the API is very straight-forward. The instructions below describe the steps for setting up and running a basic Node.js example with Backendless. The example demonstrates registering a user with your Backendless application. It gathers email address and password and uses the User Registration API call to create an account.
node example.js
The source code of the example is below (double-click the code to remove the highlighting, or click the <> button to toggle it):
var Backenless = require("./backendless"); var readline = require('readline'); var appId = 'COPY YOUR APP ID HERE'; var secretKey = 'COPY YOUR SECRET KEY HERE'; var appVer = 'v1'; Backendless.initApp( appId, secretKey, appVer ); var user = new Backendless.User(); var rl = readline.createInterface({ input: process.stdin, output: process.stdout }); rl.question( "input email address ", function( answer ) { user.email = answer; rl.question( "input password ", function( answer ) { user.password = answer; console.log( "please wait ..." ); rl.close(); try { console.log( "Registering user account : ", user ); var register = Backendless.UserService.register(user, new Backendless.Async(function( data ){ console.log( "server data ", data ); console.log( "User successfully created ", user ); },function( e ) { e = e || {}; console.log(e.massage || "Unable to register user" ); } )); } catch( e ) { console.log( e.message ); } }); });
Have fun and please let us know if you run into any problems!