Docs Menu

Docs HomeRealm

Install Realm for Node.js

On this page

  • Overview
  • Prerequisites
  • Installation
  • Create a Node.js Project
  • Install Realm with NPM
  • Enable TypeScript (optional)
  • IoT Installation
  • Install a C++ Compiler
  • Create a Node.js Project
  • Install Realm with NPM
  • Enable TypeScript (optional)
  • Import Realm

The Realm Node.js SDK enables development of applications using the JavaScript and TypeScript languages. Realm on Node.js is best suited for writing server-side applications. Your Node.js application could be one component in a wider stack that also includes iOS and Android apps.

The Realm Node.js SDK is not suitable for front-end application development.

  • Due to limitations of the browser environment, it is not possible to build a browser-based web app with this SDK. For front-end web applications, use the Realm Web SDK.

  • For cross-platform mobile app development, use the Realm React Native SDK.

Before getting started, ensure your environment meets the following prerequisites:

  • Node.js version 12.x or later (including Node.js version 14)

  • Linux, macOS 10.8 (or later), or Windows 8 (or later)

Follow these steps to create a Node.js project and add the Realm Node.js SDK to it.

1

Create your Node.js project by creating a new directory for your project and running npm init in that directory. In the example below, replace MyRealmApp with your desired project name. Answer all of the prompts to fill out the details of your project.

mkdir MyRealmApp && cd MyRealmApp && npm init
2

In your Node.js project directory, use the following command to add Realm to your project:

npm install realm
3

TypeScript is a superset of JavaScript that adds static type checking and other features intended to make application-scale development more robust. If you'd like to use TypeScript, follow the TypeScript team's official Node Starter guide. Realm supports TypeScript natively and integrates easily into a TypeScript project.

To create a Node.js project and add the Realm Node.js SDK on an Internet of Things (IoT) platform such as the Raspberry Pi 2, 3, or 4 running Raspberry Pi OS (formerly Raspbian), follow the steps below:

1

The Realm IoT SDK is not distributed as a binary, so you must build it from source. To do this, you'll need a working C++ compiler. To install such a compiler on your IoT device, run the following command:

sudo apt install build-essential g++ libssl-dev
2

Create your Node.js project by creating a new directory for your project and running npm init in that directory. In the example below, replace MyRealmApp with your desired project name. Answer all of the prompts to fill out the details of your project.

mkdir MyRealmApp && cd MyRealmApp && npm init
3

In your Node.js project directory, use the following command to add Realm to your project:

npm install realm
4

TypeScript is a superset of JavaScript that adds static type checking and other features intended to make application-scale development more robust. If you'd like to use TypeScript, follow the TypeScript team's official Node Starter guide. Realm supports TypeScript natively and integrates easily into a TypeScript project.

Add the following line to the top of your source files (JavaScript or TypeScript) where you want to use Realm:

import Realm from "realm";
←  Realm - Node.js SDKQuick Start - Node.js SDK →
Share Feedback