Skip to content

Advanced Quick Start

This quick start is an "alternative path" of the Basic Quick Start guide. In the basic guide the code is modified and deployed to Backendless servers directly from Backendless Console. In this guide you will learn how to:

  • download the generated code from Backendless console
  • modify the code and run in the debug mode
  • deploy the code to Backendless servers.
  • To get started, go through the steps 1-9 of the Basic Quick Start guide.
  • Click the Download link and select JS
  • Extract the files from the downloaded archive.
  • Open a command prompt/terminal window and change to the project's root directory. Run the following command which will install Backendless CodeRunner and Backendless SDK for JS:

npm install
1. Open /handlers/persistence/order/beforeCreate.js in a text/code editor and modify the file as shown below:
* @param {Object} req The request object contains information about the request
* @param {Object} req.context The execution context contains an information about application, current user and event
* @param {Order} req.item An item to create
* @returns {Order|Promise.<Order>|void} By returning a value you can stop further event propagation and return
*          a specific result to the caller
Backendless.ServerCode.Persistence.beforeCreate('Order', function(req) {
  console.log( "Received order object. Customer name - " + req.item.customername );
  req.item.customername = req.item.customername.toUpperCase();

  1. Save the file. Return to the command prompt/terminal window and run the following command:

npm run debug
1. The command starts CodeRunner starts, it produces the following output (the CodeRunner version number may be different):

your-comp-name:bin username$  npm run debug

> OrderManagement-servercode@1.0.0 debug /Users/mark/Downloads/OrderManagement
> coderunner debug

13:56:01.272 - CodeRunner(tm) Backendless JavaScript CodeRunner v4.3.0-beta.5
13:56:01.273 - Copyright(C) 2017 Backendless Corp. All rights reserved.
13:56:01.335 - Starting Debug Code Runner...
13:56:01.335 - Building Model..
13:56:01.337 - Reading handlers/persistence/order/beforeCreate.js...
13:56:01.338 - Reading models/order.js...
13:56:01.625 - Model Build completed
13:56:01.626 - Event handlers (1):
13:56:01.626 -   persistence.beforeCreate (Order) (handlers/persistence/order/beforeCreate.js)
13:56:01.626 - Custom Types (1):
13:56:01.626 -   Order (models/order.js)
13:56:01.791 - Registering Code Runner on
13:56:02.192 - Runner successfully registered.
13:56:02.193 - Registering Model on
13:56:02.474 - Model successfully registered
13:56:02.474 - Waiting for Server Code tasks..

  1. At this point CodeRunner™ is connected to Backendless and the code is ready for local debugging. Return to Backendless Console and refresh the EVENT HANDLERS screen. You will see the event handler in the debug mode:
  2. To test the event handler, return to the Basic Quick Start and follow the instructions from step 13.
  3. When an event handler is in the debug mode and receives API events, it produces additional output which may be helpful for debugging purposes:

14:30:01.905 - [C47C55FA-926D-F386-FFDE-188529D3EF00] New task arrived!
14:30:01.911 - [C47C55FA-926D-F386-FFDE-188529D3EF00] [INVOKE HANDLER] persistence.beforeCreate (Order)
Received order object. Customer name - foobar corp
14:30:01.915 - [C47C55FA-926D-F386-FFDE-188529D3EF00] Processing finished

  1. You can stop the debug mode by entering Ctrl+C. To deploy the code from the developer's computer to Backendless servers, run the following command:

npm run deploy
1. When the code is being deployed, CodeRunner produces the following output. Notice how individual event handlers and recognized custom types are listed in the program output:

npm run deploy

> OrderManagement-servercode@1.0.0 deploy /Users/mark/Downloads/OrderManagement
> coderunner deploy

14:31:39.272 - CodeRunner(tm) Backendless JavaScript CodeRunner v4.3.0-beta.5
14:31:39.273 - Copyright(C) 2017 Backendless Corp. All rights reserved.
14:31:39.322 - Building Model..
14:31:39.323 - Reading handlers/persistence/order/beforeCreate.js...
14:31:39.324 - Reading models/order.js...
14:31:39.657 - Model Build completed
14:31:39.657 - Event handlers (1):
14:31:39.657 -   persistence.beforeCreate (Order) (handlers/persistence/order/beforeCreate.js)
14:31:39.658 - Custom Types (1):
14:31:39.658 -   Order (models/order.js)
14:31:39.658 - Preparing app zip file for deployment..
14:31:40.062 - 2 files added into deployment archive
14:31:40.067 - Publishing Model to server
14:31:42.772 - Successfully published

  1. When the event handler is deployed, it will appear in Backendless Console with the green color-code (indicating the production deployment):event-handler-production-deployment.zoom73