This is my code on Node Js
'use strict';
const fs = require('fs');
const Realm = require('realm');
// the URL to the Realm Object Server
const SERVER_URL = '//instance.cloud.realm.io:9080';
const adminCreds = Realm.Sync.Credentials.usernamePassword('Administrator', 'password', false);
// The regular expression you provide restricts the observed Realm files to only the subset you
// are actually interested in. This is done in a separate step to avoid the cost
// of computing the fine-grained change set if it's not necessary.
var NOTIFIER_PATH = '.*';
//declare admin user
let adminUser = undefined
// The handleChange callback is called for every observed Realm file whenever it
// has changes. It is called with a change event which contains the path, the Realm,
// a version of the Realm from before the change, and indexes indication all objects
// which were added, deleted, or modified in this change
var handleChange = async function (changeEvent) {
console.log("this is a change");
}
function verifyCouponForUser(coupon, userId) {
//logic for verifying a coupon's validity
}
async function login(serverUrl,user) {
let result = await Realm.Sync.User.login(serverUrl,user);
return result;
}
// register the event handler callback
async function main() {
try{
adminUser = await login('https://instance.cloud.realm.io',adminCreds);
Realm.Sync.addListener(`realms:${SERVER_URL}`, adminUser, NOTIFIER_PATH, 'change', handleChange);
}catch(e) {
console.log('error');
console.log(e);
}
}
main()
That’s all. and I got this: “Sync connection was not fully established in time” after 2 minutes. in console.
I add an element to the realm and try to save the response into a file.txt but nothing happens.
It suppose, if I set NOTIFIER_PATH = ‘.*’; it will listen to all realms already created for updates.
Thanks in advance!!