Skip to main content

Getting Started

This guide will help you set up Sentro in your project and create your first database management API.

Installation

Install the core packages using npm or yarn:

npm install @sentrodb/connector-node @sentrodb/connector-helper-sql
# or
yarn add @sentrodb/connector-node @sentrodb/connector-helper-sql

Prerequisites

  • Node.js 16+ installed
  • A database (PostgreSQL, MySQL, or MSSQL)
  • TypeScript project (recommended)
  • Basic knowledge of async/await

Basic Setup

1. Create a Connector Instance

First, create and configure your connector instance:

import Connector from "@sentrodb/connector-node";
import ConnectorHelperSql from "@sentrodb/connector-helper-sql";

const connector = new Connector({
  secretKey: process.env.CONNECTOR_SECRET_KEY!,
  db: {
    host: process.env.DB_HOST!,
    port: parseInt(process.env.DB_PORT!),
    user: process.env.DB_USER!,
    password: process.env.DB_PASSWORD!,
    database: process.env.DB_NAME!,
    schema: "public", // PostgreSQL only
    type: "postgres" // or "mysql" or "mssql"
  }
});

2. Set Database Handler

Initialize the database connection:

await connector.setDatabaseHandler(new ConnectorHelperSql());

3. Start the Connector

This introspects your database schema and prepares the API:

await connector.start();

4. Mount on Your Framework

Choose your preferred framework:

NestJS

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  // ... connector setup ...

  connector.mountOnNestJs(app);
  await app.listen(4000);
}
bootstrap();

Express

import express from 'express';

const app = express();

// ... connector setup ...

connector.mountOnExpress(app);
app.listen(4000);

Fastify

import fastify from 'fastify';

const app = fastify();

// ... connector setup ...

connector.mountOnFastify(app);
await app.listen({ port: 4000 });

Standalone Server

// ... connector setup ...

connector.startStandaloneServer({ port: 4000 });

Complete Example

Here's a complete working example with NestJS:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import Connector from "@sentrodb/connector-node";
import ConnectorHelperSql from "@sentrodb/connector-helper-sql";

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const connector = new Connector({
    secretKey: process.env.CONNECTOR_SECRET_KEY!,
    authKey?: "auth",
    db: {
      host: "localhost",
      port: 5432,
      user: "postgres",
      password: "password",
      database: "mydb",
      schema: "public",
      type: "postgres"
    }
  });

  await connector.setDatabaseHandler(new ConnectorHelperSql());
  await connector.start();

  connector.mountOnNestJs(app);
  await app.listen(4000);

  console.log(`Application is running on: http://localhost:4000`);
  console.log(`Connector API: http://localhost:4000/dbmanager`);
}

bootstrap();

Testing Your API

Once running, you can access the auto-generated health endpoint at:

Health API

GET http(s)://<your-host>/dbmanager/health
Next Steps: Learn about Configuration options to customize your setup.