Quick Start Guide for using Backendless with TypeScript

This guide will help you get up and running with Backendless quickly so you can develop TypeScript applications on top of our services. At the end of the guide you will have a configured working environment and a basic project with the code communicating with the Backendless services.

  1. Login to your Backendless account or register to create a new one.
  2. Install node and npm
  3. Create a new TypeScript application project.
  4.  Create  package.json file with the following contents in the root of your application directory:
  5. Create  tsconfig.json file in the root directory of the project with the following contents:
  6. Create index.html  file:
  7. Create  app.ts file which will contain your TypeScript code. The file for now will have just one line:
  8. At this point your environment is configured. To finalize it, run the following command:
  9. Once all the packages are installed, run the command below:
  10. Get your Backendless application keys for Backendless SDK for JavaScript from the Backendless Console. The keys can be found in the Manage > App Settings section:js keys - Quick Start Guide for using Backendless with TypeScript
  11. Copy/paste the application ID and JavaScript secret key into the code and add the Backendless application initialization code into app.ts right after the “reference” line added in step 7:

At this point the application has the bare minimum required code to work with Backendless. The steps below will demonstrate how to use various Backendless APIs:

User Registration

  1. Add the following code to app.ts. The code should be added before the closing curly bracket, right where the comment says “//more code will be added here”. The code registers a user in your app’s backend. Instead of used in the code below, consider using an email address  where you can check email – your Backendless backend will send out an email welcoming the user to your app.
  2. Open index.html  in a browser – you can open it by double-clicking the file in the file system. Once a browser opens the file, it runs the code which registers the user.
  3. You can verify the registered user in the Data section of the Backendless Console:
    new user created - Quick Start Guide for using Backendless with TypeScript

Data Persintence

  1. In order to experience the Backendless Data Service API declare a new class. Instances of the class can be saved using the Backendless API. The class is going to be called Comment, it will also correspond to a table with the same name. The code below can be added in app.ts  right after user registration logic:
  2. The code below obtains Backendless.DataStore  object for a table corresponding to the Comment  class. The object is used to store instance of Comment  in Backendless. Add the following code into app.ts . It should be added right after Comment  class declaration.
  3. Save the file and reload index.html  in the browser which will run the code you just added.
  4. Now you can verify in the Backendless Console that the Comment data table has been created with the columns corresponding to the properties of the Comment class and it contains the saved instance.
    comment record - Quick Start Guide for using Backendless with TypeScript

Finally all your code should look like this: