RethinkDB: Connecting Node.js to RethinkDB

This documentation is part of the Getting started guide. You can view the complete guide here: Learn how to configure and secure your RethinkDB instance on Stackhero.

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use RethinkDB cloud solution that provides a host of benefits, including:

  • Effortless updates with just a click.
  • Optimal performance and robust security powered by a private and dedicated VM.

Save time and simplify your life: it only takes 5 minutes to try Stackhero's RethinkDB cloud hosting solution!

Since connections to RethinkDB are secured with TLS, and the official RethinkDB client library does not support TLS, it is recommended to use the rethinkdbdash library instead.

You can install rethinkdbdash with npm:

npm install rethinkdbdash

Here is a simple example showing how to connect your Node.js application to your RethinkDB database. This configuration includes server details such as host and port, connection limits, and SSL settings.

const rethinkdbdash = require('rethinkdbdash');

const r = rethinkdbdash({
  servers: [
    {
      host: '<XXXXXX>.stackhero-network.com',
      port: 28015
    }
  ],
  ssl: true,
  buffer: 20, // Minimum number of connections to keep open
  max: 100,   // Maximum number of connections
  timeoutGb: 30 * 1000, // Time (ms) to keep unused connections
  db: '<DATABASE>',
  authKey: '<PASSWORD>',
  // silent: true, // You can uncomment this line to disable logging on stderr
});

Replace <XXXXXX>, <DATABASE>, and <PASSWORD> with your own values.

By following these steps, your RethinkDB instance will be secured and ready to use on Stackhero. If you have any questions or need further assistance, please feel free to contact our support team.