Navigation

Open & Close a Local Realm - Node.js SDK

To open a local (non-synced) realm, pass a Realm.Configuration object to Realm.open().

Note
Accessing the Default Realm Path

If the path property is not specified in your Configuration object, the default path is used. You can access and change the default Realm path using the Realm.defaultPath global property.

// Open a local realm file with a particular path & predefined Car schema
const realm = await Realm.open({
path: "myrealm",
schema: [Car],
});

In the above example, the code shows how to open the realm asynchronously by calling realm.open(). You can also open a realm synchronously by passing a Configuration object to a new instance of the Realm object. This works even if the device is offline.

// Synchronously open a local realm file with a particular path & predefined Car schema
const realm = new Realm({
path: "myrealm",
schema: [Car],
});
Note

The first time a user logs on to your realm app, you should open the realm asynchronously to sync data from the server to the device. After that initial connection, you can open a realm synchronously to ensure the app works in an offline state.

It is important to remember to call the close() method when done with a realm instance to avoid memory leaks.

realm.close();
Give Feedback