Docs Menu
Docs Home
/ /
Atlas Device SDKs

Quick Start - Web SDK

On this page

  • Overview
  • Install the Web SDK
  • Import the Web SDK
  • Initialize the App
  • Authenticate a User
  • Call a Function

This page shows you how to connect the Realm Web SDK to an Atlas App Services backend, authenticate a user, and work with data. Before you begin, you'll need to create an App for your web app to use.

npm install realm-web
yarn add realm-web

Add a <script> tag to the <head> of your HTML file to load the Realm Web SDK as a global variable from a content delivery network.

Use the most recent version:

<script src="https://unpkg.com/realm-web/dist/bundle.iife.js"></script>

Or import a specific version:

<script src="https://unpkg.com/realm-web@1.5.1/dist/bundle.iife.js"></script>

Near the top of any JavaScript or TypeScript file that uses Realm, add the following import statement:

import * as Realm from "realm-web";

Note

If you loaded the SDK using a <script> tag then you don't need to import the SDK to use it. Instead, you can access it using the global Realm variable.

To use App Services features such as authentication and sync, access your App Services App using your App ID. You can find your App ID in the App Services UI.

// Add your App ID
const app = new Realm.App({ id: APP_ID });

When anonymous authentication is enabled, users can log into your app without providing any identifying information:

// Create an anonymous credential
const credentials = Realm.Credentials.anonymous();
// Authenticate the user
const user = await app.logIn(credentials);
// `App.currentUser` updates to match the logged in user
console.assert(user.id === app.currentUser.id);

App Services provides many additional ways to authenticate, register, and link users.

Tip

See also:

To call a function, use the Realm.User.functions interface to call your serverless functions as if they were regular JavaScript functions defined on the object.

const summed = await user.functions.sum(2, 3);
console.assert(summed === 5);

Next

Welcome to the Atlas Device SDK Docs