Introduction
Welcome to the ultimate guide for RepoDB. In this tutorial, we won't just show you how to connect; we'll show you how to build a production-grade integration. The best way to interact with RepoDB is through our official Node.js client SDK, which handles authentication, retries, and error parsing for you.
Step 1: Installation
Install the client using your preferred package manager:
npm install @suman-malik-repo/repodb-client
# or
yarn add @suman-malik-repo/repodb-client
Step 2: Obtaning Credentials
Security is paramount. You need an API token to talk to your database.
- Log in to your RepoDB Cloud Dashboard.
- Go to Settings > API Tokens.
- Click Generate New Token. Select "Read/Write" permissions if you intend to modify data.
- Copy this token immediately. For security reasons, we never show it again.
Step 3: Best Practices for Connection
Never hardcode your secrets. Use environment variables.
// config.js
import dotenv from 'dotenv';
dotenv.config();
export const dbConfig = {
host: process.env.REPODB_HOST || 'https://repodb.ogensync.com',
token: process.env.REPODB_TOKEN
};
Now, initialize the client. The RepoDB client is lightweight and stateless, so you don't need to worry about managing heavy connection pools like you do with Postgres.
import Repodb from '@suman-malik-repo/repodb-client';
import { dbConfig } from './config.js';
const db = new Repodb(dbConfig);
// Test the connection
try {
const health = await db.execute('SELECT 1 as val');
console.log('Database connected!', health.rows[0]);
} catch (err) {
console.error('Connection failed:', err.message);
}
Note: If you are using our Managed Cloud, the host is always https://repodb.ogensync.com. We route you to your specific bucket automatically based on your token.