Realm-js: Electron and sandboxing on macOS

Created on 26 Jan 2017  路  9Comments  路  Source: realm/realm-js

Bindings should handle if it's build for using in Electron app and use the system API to get writable directories for any internal data in sandbox.

Right now realm-object-server is created in the working directory that crashes the app.

T-Bug

Most helpful comment

+1 for this feature! We are releasing an offline first desktop app in April so hanging out for this!

All 9 comments

Just wanted to mention that changing the working directory before requiring realm the app will work.

process.chdir('/directory/outside/app/folder')
const realm = require('realm')

Edit:

My point is as a workaround, you can change the cwd before require('realm') that will create realm-object-server in the new cwd and avoid the sandboxing issue.

The new cwd should be outside the .app directory, for example in main file:

import { app, BrowserWindow } from 'electron'
process.chdir(app.getPath('userData'))

@Ted-Mohamed _process.chdir will not have effect on the require if it is written like that.
Check the module require high-level algorithm here:
https://nodejs.org/api/modules.html#modules_all_together_

ignore the above. I misunderstood your comment

@blagoev it's okay, english is not my native language. Sorry I was not so clear. I edited my comment.

+1 for this feature! We are releasing an offline first desktop app in April so hanging out for this!

@kneth is there a way through the Realm JS API to choose where the realm-object-server data is stored?

@kraenhansen Currently, no. realm-object-server is fixed and its location is specific to the platform (Android, iOS, Node.js).

for those who are still facing this issue, you can set db path in path the configuration you are passing while opening realm connection.
you can get the user home path in electron with, and create new db path

const remote = require("electron").remote;
const dbpath = path.join(
  app.getPath("home"),
  "data.realm"
);

add the new db path to the config options.

eg:

const dbConfig: Realm.Configuration = {
  schema: [Person],
  deleteRealmIfMigrationNeeded: true,
  path: dbpath,
  // path: "./.db/shdb/data.realm",
};

then the db will be created in home dir, in the specified location . hope this helps.

for those who are still facing this issue, you can set db path in path the configuration you are passing while opening realm connection.
you can get the user home path in electron with, and create new db path

const remote = require("electron").remote;
const dbpath = path.join(
  app.getPath("home"),
  "data.realm"
);

add the new db path to the config options.

eg:

const dbConfig: Realm.Configuration = {
  schema: [Person],
  deleteRealmIfMigrationNeeded: true,
  path: dbpath,
  // path: "./.db/shdb/data.realm",
};

then the db will be created in home dir, in the specified location . hope this helps.

As there are no official support/docs for the realm to be included in the electron as local DB, Can you please tell me what is the best approach to be followed i.e include it in main or renderer?

  1. Is it possible to sync the realm DB with MongoDB when it is connected to the internet by following your approach?

there is an electron quickstart here -
https://docs.mongodb.com/realm/node/electron

Was this page helpful?
0 / 5 - 0 ratings