Skip to main content

Installation

npm install @databite/server @databite/connect
# Optional
npm install @databite/build @databite/connectors @databite/engine @databite/types

1) Start your server

Create and run a Databite server. Add integrations using built-in or custom connectors.
import { DatabiteServer } from "@databite/server";
import { InMemoryAdapter } from "@databite/engine";
import { slack } from "@databite/connectors";

async function main() {
  const server = new DatabiteServer({
    port: 3001,
    engineConfig: {
      schedulerAdapter: new InMemoryAdapter(),
      minutesBetweenSyncs: 10,
    },
  });

  await server.addIntegration(
    slack.createIntegration("Slack Integration", {
      clientId: process.env.SLACK_CLIENT_ID!,
      clientSecret: process.env.SLACK_CLIENT_SECRET!,
      redirectUri: process.env.SLACK_REDIRECT_URI!,
      scopes: ["chat:write", "channels:read"],
    })
  );

  await server.start();
  console.log("Server running at http://localhost:3001");
}

main().catch(console.error);

2) Connect from your frontend

Use the React modal to authenticate and create a connection via your server.
import React, { useState } from "react";
import { ConnectModal } from "@databite/connect";

export default function Page() {
  const [open, setOpen] = useState(false);

  return (
    <>
      <button onClick={() => setOpen(true)}>Connect to Slack</button>
      <ConnectModal
        open={open}
        onOpenChange={setOpen}
        // If your client knows the integrationId and server URL:
        integrationId="slack-integration-id"
        baseUrl={process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001"}
        onAuthSuccess={async (integration, connectionConfig) => {
          // Persist connection to your backend
          await fetch("/api/save-connection", {
            method: "POST",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify({ integrationId: integration.id, connectionConfig }),
          });
        }}
        onAuthError={(e) => console.error(e)}
      />
    </>
  );
}

Optional: Sync jobs

Use @databite/engine on the server for scheduled syncs. See the Engine page for details.

Next Steps