Realm is a mobile database that runs directly inside phones, tablets or wearables. This project hosts the JavaScript versions of Realm. Currently we support React Native (both iOS & Android), Node.js and Electron (on Windows, MacOS and Linux)
- Mobile-first: Realm is the first database built from the ground up to run directly inside phones, tablets and wearables.
- Simple: Data is directly exposed as objects and queryable by code, removing the need for ORM's riddled with performance & maintenance issues.
- Modern: Realm supports relationships, generics, and vectorization.
- Fast: Realm is faster than even raw SQLite on common operations, while maintaining an extremely rich feature set.
Please see the detailed instructions in our docs to use Realm JavaScript for node.js and Realm JavaScript for React Native. Please notice that currently only node.js version 10 or later (excluding 11) are supported.
The documentation can be found at docs.mongodb.com/realm/react-native/. The API reference is located at docs.mongodb.com/realm-sdks/js/latest/.
- Need help with your code?: Look for previous questions on the #realm tag — or ask a new question. You can also check out our Community Forum where general questions about how to do something can be discussed.
- Have a bug to report? Open an issue. If possible, include the version of Realm, a full log, the Realm file, and a project that shows the issue.
- Have a feature request? Open an issue. Tell us what the feature should do, and why you want the feature.
In case you don't want to use the precompiled version on npm, you can build Realm yourself from source. You’ll need an Internet connection the first time you build in order to download the core library.
Prerequisites:
- Xcode 12+
- node.js version 10.19 or later
- nvm (on Mac and Linux)
- cocoapods (on Mac)
- Android SDK 23+
- Android NDK 21.0
- Available via the SDK Manager in Android Studio Tools > SDK Manager.
- From the command-line:
$ANDROID_HOME/tools/bin/sdkmanager --install "ndk;21.0.6113669"
.
Clone RealmJS repository:
git clone https://github.com/realm/realm-js.git
cd realm-js
git submodule update --init --recursive
Note: On Windows the RealmJS repo should be cloned with symlinks enabled
#run in elevated command prompt
git clone -c core.symlinks=true https://github.com/realm/realm-js
or manually create the symlinks using directory junctions if you already have the repo cloned.
#run in elevated command prompt
cd realm-js\react-native\android\src\main\jni
#remove src and vendor files
del src
del vendor
mklink /j "src" "../../../../../src/"
mklink /j "vendor" "../../../../../vendor"
cd realm-js\tests\react-test-app\android\app\src\main
#remove assets file
del assets
mklink /j assets "../../../../../data"
Note: If you have cloned the repo previously make sure you remove your node_modules directory since it may contain stale dependencies which may cause the build to fail.
- Open
react-native/ios/RealmReact.xcodeproj
in Xcode - Select
RealmReact
underTargets
- Build:
⌘ + B
cd react-native/android
export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/21.0.6113669 #Location for your NDK folder
./gradlew publishAndroid
- The compiled version of the Android module is here:
<project-root>/android
Be sure you have python2.7 as the default python. 3.x won't work, and it's not enough to use --python=python2.7
as parameter to npm.
For example you can use Homebrew to install it.
brew install python@2
npm install --build-from-source=realm
On Windows you will need to setup the environment for node-gyp:
-
Option 1: Install windows-build-tools node package
# run in elevated command prompt (as Administrator) npm install -g --production windows-build-tools
-
Option 2: Manually install and configure as described in the node-gyp manual.
Note you may need to configure the build tools path using npm
npm config set msbuild_path "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"
You also need to install openssl libraries with vcpkg:
git clone https://github.com/Microsoft/vcpkg
cd vcpkg
bootstrap-vcpkg.bat
vcpkg install openssl:x64-windows-static
mkdir C:\src\vcpkg\installed\x64-windows-static\lib
copy .\packages\openssl-windows_x64-windows-static\lib\libeay32.lib C:\src\vcpkg\installed\x64-windows-static\lib\
copy .\packages\openssl-windows_x64-windows-static\lib\ssleay32.lib C:\src\vcpkg\installed\x64-windows-static\lib
We've decided to slowly migrate this repository to a mono-repository containing multiple packages (stored in the ./packages
directory), to install & link these, run
npx lerna bootstrap
Please familiarise yourself with Lerna to learn how to add dependencies to these packages.
API documentation is written using JSDoc.
npm run jsdoc
The generated docs can be found by opening docs/output/realm/<version>/index.html
.
You can use Visual Studio Code to develop and debug. In the .vscode
folder, configuration for building and debugging has been added for your convience.
VSCode has good support for debugging JavaScript, but to work with C++ code, you are required to install two additional VSCode extensions:
- Microsoft C/C++
- CodeLLDB
To begin, you will need to build the node addon and prepare the test environment:
npm install --build-from-source --debug
(cd tests && npm install)
Prior to begin debugging, you must start Realm Object Server. In VSCode, under menu Tasks/Run Task, find Download and Start Server.
In the debugging pane, you can find Debug LLDB + NodeJS
in the dropdown. First select Start Debugging in the Debug menu.
Some users have reported the Chrome debugging being too slow to use after integrating Realm into their react-native project. This is due to the blocking nature of the RPC calls made through the Realm library. See realm#491 for more information. The best workaround is to use Safari instead, as a user has described here.
The tests will spawn a new shell when running, so you need to make sure that new shell instances use the correct version of npm
. On Mac you can use Homebrew and you can add the following to your prefered shell setup:
export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"
Install cocoapods
sudo gem install cocoapods
You can now use scripts/test.sh
to run the various tests.
You will need yarn installed on the machine.
test.sh
options
- eslint - lints the sources
- react-tests - runs all React Native tests on iOS Simulator
- react-tests-android runs all React Native Android tests on Android emulator
- node - runs all tests for node
- test-runners - checks supported tests runners are working correctly
If you modify or add a test, please remove tests/react-test-app/node_modules/realm-tests
before running test.sh
(of course, only if you are testing with React Native).
On Windows some of these targets are available as npm commands.
npm run eslint
npm run node-tests
npm run test-runners
You can attach a debugger to react-native tests by passing "Debug" to the test.sh
script. A Chrome browser will open and connect to the react native application. Use the built-in Chrome Debugger to debug the code.
./scripts/tests.sh react-tests Debug
Using Visual Studio Code
You can debug node tests using Visual Studio Code. Just use one of the launch configurations.
This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].
See CONTRIBUTING.md for more details!
Realm JS is published under a mix of the Apache License 2.0 and the Realm Platform Extensions License. Realm Core is published under the Apache 2.0 license and is available here.
This product is not being made available to any person located in Cuba, Iran, North Korea, Sudan, Syria or the Crimea region, or to any other person that is not eligible to receive the product under U.S. law.
If you use Realm and are happy with it, all we ask is that you please consider sending out a tweet mentioning @realm to share your thoughts
And if you don't like it, please let us know what you would like improved, so we can fix it!