JavaScript

Install Parse SDK to your JavaScript Project

Introduction

In this section you learn how to install Parse JavaScript SDK into your HTML project.

See more about Parse SDK at Parse JavaScript SDK API Reference and Parse open source documentation for JavaScript SDK.

Prerequisites

To complete this tutorial, you will need:

Parse JavaScript SDK supports Firefox 23+, Chrome 17+, Safari 5+, and IE 10.
IE 9 is supported only for apps that are hosted with HTTPS.

Step 1 - Install SDK

The unpkg is a delivery network that makes working with bundled npm modules easier. To install Parse JavaScript SDK, open your index.html file and simply add the following script inside its <head> tag:

index.html

1
<script src="https://unpkg.com/parse/dist/parse.min.js"></script>

Step 2 - Connect your Parse App

Initialize your Parse app

Use Parse.Initialize method to set up the authentication token, connecting your page with Back4App servers.

Go to your index.html file and inside <script> tag add the following code:

index.html

1
2
Parse.initialize("YOUR_APP_ID", "YOUR_JS_KEY"); //PASTE HERE YOUR Back4App APPLICATION ID AND YOUR JavaScript KEY
Parse.serverURL = "https://parseapi.back4app.com/";

Find your Application ID and your Client Key

  1. Go to your App Dashboard at Back4App website.
  2. Navigate to app’s settings: Click on Server Settings > Core Settings block > Settings.
  3. Return to your Parse.Initialize function and paste your applicationId and javaScriptKey.

Step 3 - Test your conection

Create a test code

Test your initial setup with the following code which creates a new object of the User class.

Add it inside <script> tag, right after Parse.initialize method:

index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
var user = new Parse.User();
user.save({
  username: 'sampeusername',
  email: '[email protected]',
  password: '123456'
}, {
  success: function(response) {
    alert('New object create with success! ObjectId: ' + response.id + `, ` + user.get('username'));
  },
  error: function(response, error) {
    alert('Error: ' + error.message);
  }
});
  1. Open your HTML file in your web browser.
  2. An alert box will show the id of the new User object that was created.
  3. Log in at Back4App.
  4. Find your app and click on Dashboard.
  5. Click on Core.
  6. Go to Browser.
  7. Click on User class.
  8. Check your new object there.

Parse Dashboard - Class User

It’s done!

At this point, you have learned how to get started with JavaScript web apps.

Learn more by walking around Parse open source documentation for JavaScript SDK.