> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/ai/manage-documents/javascript-typescript.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# JavaScript / TypeScript

Full CRUD for the DNotifier knowledge base over HTTP.

## Setup

```js
import { DNotifier } from "@dnotifier-realtime/dnotifier";

const USER_ID = "indexer-service";

const notifier = new DNotifier({
  appId: process.env.DNOTIFIER_APP_ID,
  secret: process.env.DNOTIFIER_SECRET,
  transport: "http",
  userId: USER_ID,
  onConnected: () => {},
  onMessage: () => {},
  onDisconnected: () => {},
});

await notifier.connect();
```

## Add

```js
await notifier.addDocument({
  senderId: USER_ID,
  recordId: "refund-policy",
  content:
    "Refund requests are processed within 5 business days after approval.",
  type: "text",
  metadata: { source: "help-center", locale: "en" },
});
```

## Update

```js
await notifier.updateDocument({
  senderId: USER_ID,
  recordId: "refund-policy",
  content:
    "Refund requests are processed within 3 business days after approval.",
  type: "text",
  metadata: { source: "help-center", locale: "en", version: 2 },
});
```

## Get one document

```js
const doc = await notifier.getDocument({
  senderId: USER_ID,
  recordId: "refund-policy",
});
console.log(doc);
```

## List (paginated)

```js
const list = await notifier.listDocuments({
  senderId: USER_ID,
  limit: 20,
  offset: 0,
  type: "text",
});
console.log(list);
```

## Delete

```js
await notifier.deleteDocument({
  senderId: USER_ID,
  recordId: "refund-policy",
});
```

## Batch import script

```js
const articles = [
  { id: "faq-password", content: "Reset password from Settings → Security." },
  { id: "faq-billing", content: "Invoices are emailed on the 1st of each month." },
];

for (const article of articles) {
  await notifier.addDocument({
    senderId: USER_ID,
    recordId: article.id,
    content: article.content,
    type: "faq",
    metadata: { source: "help-center" },
  });
  console.log("Indexed:", article.id);
}
```

## Learn more

* [**Semantic search**](https://dnotifier.gitbook.io/product-docs/ai/semantic-search/javascript-typescript.md)
* [**Example: RAG bot**](https://dnotifier.gitbook.io/product-docs/ai/example-rag-bot/javascript-typescript.md)
