Running the Server

1
Last updated 6 months ago

Running the Server

Realm Object Server is a Node package which requires a Node project to run within. To make it easy to get going, the installation includes a command-line interface to bootstrap a project for you!

Create a new ROS project instance:

ros init my-app

This creates a Typescript-based Node project for you. Later on you can explore customizing it but for now simply start the server with defaults by:

If you have trouble running a ros command it may be due to your version of NVM. Try running nvm use 8 in your terminal.

1) Add your feature token:

Starting with Realm Object Server 3.5.0, a feature token is required to run the server. You can get your own feature token here.

From inside of your project folder, you'll need to open the index file which can be found at src/index.tsYou'll need to paste in your feature token as shown below:

import { BasicServer, FileConsoleLogger } from 'realm-object-server'
import * as path from 'path'
const server = new BasicServer()
server.start({
// ..
featureToken: '<INSERT YOUR FEATURE TOKEN HERE>',
//....
})

2) Start the server

cd my-app/
npm start

That’s it! You now have a functioning Realm Object Server running locally on port 9080! The server is tied to your terminal window for now and can be stopped by pressing Ctrl-C.

Click here for more information on the command-line interface for ROS.

Running ROS in the Background

Once you are ready to go into production, you will want to daemonize your application project so that it runs in the background and automatically on server startup. We recommend using pm2 to maintain instances of Realm Object Server in production. PM2 is a battle tested process manager that allows your applications to stay alive forever and helps with mission critical administration during downtime.

Install PM2

You can install pm2 in your machine using npm with:

npm install pm2 -g

Start ROS

JavaScript
TypeScript
pm2 start path/to/myserver/src/index.js

Now your ROS instance is daemonized, monitored and kept alive forever.

You can supply a name to your started instance with the --name option:

pm2 start path/to/myserver/src/index.js --name my-ros

If you’re interested in starting the TypeScript source you’ll need to have pm2 install TypeScript via:

pm2 install typescript

You will only have to run the install once.

Then run.

pm2 start my-ros/src/index.ts

You can supply a name to your started instance with the --name option:

pm2 start my-ros/src/index.ts --name my-ros

Stop ROS

pm2 stop my-ros

Restart ROS

pm2 restart my-ros

Delete ROS

When you are no longer interested in registering a daemonized and monitored instance you can use delete:

pm2 delete my-ros

What's next - Install Realm Studio

Not what you were looking for? Leave Feedback