Remember that you fiddled with the RethinkDB changefeeds previously, using the Data Explorer from the Administration UI again at localhost:8080/#dataexplorer. To subscribe to a changefeed, you just have to chain the ReQL changes command to the query, as follows:
r.db('nuxtdb').table('user').changes()
The RethinkDB changefeeds contain real-time data that's emitted from the RethinkDB database to our API, which means we need to catch these feeds on the server-side with the Socket.IO server and emit them to the client. So, let's learn how to catch them by refactoring the API we have been developing throughout this chapter:
- Install the Socket.IO server via npm into your API:
$ npm i socket.io
- Create an asynchronous anonymous arrow function in a changefeeds.js file in the /core/ directory with the following code:
// core/database/rethinkdb/changefeeds.js
import rdb from 'rethinkdb'
import rdbConnection...