JEDev JEDev - 1 month ago 16x
Node.js Question

RethinkDB / Horizon: Integration with Express: Access Horizon data server-side?

There is an example of express integration on the Github as shown here:
Horizon express server example

I understand what this example is showing: if you have an existing Express server you can add a horizon server, which exposes a route client-side so they can connect to horizon server via websockets.

However, is there is any way for the express part of the server to also access the collections in Horizon? For example, to do things like local authentication, CRON jobs, or have API endpoints that accept PUT/POST requests.

From what I understand, a direct connection to the RethinkDB database Horizon is using is not that useful, because of a library named Fusion that is dynamically setting metadata on the tables in order to get Firebase-like behavior that Horizon is used for.

How can I access Horizon data server-side?

nwm nwm

To access the collections of Horizon you can use the @horizon/client.

npm install --save  @horizon/client

in server side code:

const Horizon = require("@horizon/client/dist/horizon");
const horizon = Horizon();

And then you can use the Horizon API: for things such as connection, Auth, and users; then use the collection API: for getting access to the same collections that the client accesses.