> ## Documentation index
> Fetch the complete documentation index at: https://novu.docs7.io/llms.txt
> Ask it with GET https://novu.docs7.io/ask?q=<keywords or question>. Short keywords rank best.
> Use these to discover all available pages before exploring further.

# Typescript

> Connect a Node.js or TypeScript application to Novu with the official server SDK to trigger workflows, manage subscribers, and send notifications.

Novu's Typescript SDK provides simple, yet comprehensive notification management, and delivery capabilities through multiple channels that you can implement using code. It integrates seamlessly with your Node.js, Bun, Deno, and Cloudflare Workers applications.

[Explore the source code on GitHub](https://github.com/novuhq/novu-ts)

## Installation

<Tabs>
<Tab title="NPM">

```bash
npm add @novu/api
```

</Tab>
<Tab title="PNPM">

```bash
pnpm add @novu/api
```

</Tab>
<Tab title="Yarn">

```bash
yarn add @novu/api zod@^3

## Note that Yarn does not install peer dependencies automatically. You will need

## to install zod as shown above.

```

</Tab>
<Tab title="Bun">

```bash
bun add @novu/api
```

</Tab>
</Tabs>

## Usage

<Tabs>
<Tab title="US Region">

```typescript
import { Novu } from "@novu/api";

const novu = new Novu({ secretKey: "<YOUR_SECRET_KEY_HERE>", });

async function run() {
  const result = await novu.trigger({
    to: {
      subscriberId: "subscriber_unique_identifier",
      firstName: "Albert",
      lastName: "Einstein",
      email: "albert@einstein.com",
      phone: "+1234567890",
    },
    workflowId: "workflow_identifier",
    payload: {
      comment_id: "string",
      post: {
        text: "string",
      },
    },
    overrides: {
      email: {
        bcc: "no-reply@novu.co",
      },
    },
  });
}

run();
```

</Tab>
<Tab title="EU Region">

```javascript
import { Novu } from "@novu/api";

const novu = new Novu({
  secretKey: "<YOUR_SECRET_KEY_HERE>",
  serverURL: "https://eu.api.novu.co",
});

async function run() {
  const result = await novu.trigger({
    to: {
      "subscriberId": "subscriber_unique_identifier",
      "firstName": "Albert",
      "lastName": "Einstein",
      "email": "albert@einstein.com",
      "phone": "+1234567890",
    },
    workflowId: "workflow_identifier",
    payload: {
      "comment_id": "string",
      "post": {
        "text": "string",
      },
    },
    overrides: {
      "email": {
        "bcc": "no-reply@novu.co"
      },
    },
  });

  // Handle the result
  console.log(result);
}

run();
```

</Tab>
<Tab title="Self-hosted">

Point the SDK at your self-hosted API by passing `serverURL`. Do not append `/v1` - the SDK adds the API version automatically.

```javascript
import { Novu } from "@novu/api";

const novu = new Novu({
  secretKey: "<YOUR_SECRET_KEY_HERE>",
  serverURL: "https://your-novu-api-host", // e.g. http://localhost:3000
});
```

If you use Novu Cloud (US default), omit `serverURL` entirely - the SDK points to `https://api.novu.co`.

</Tab>
</Tabs>

## Sending custom header

To send custom headers, you can use the `HTTPClient` class. Read more on how to configure custom [http client](https://github.com/novuhq/novu-ts?tab=readme-ov-file#custom-http-client).

```typescript
import { Novu } from "@novu/api";
import { HTTPClient } from "@novu/api/lib/http";

const httpClient = new HTTPClient();

httpClient.addHook("beforeRequest", (request) => {
  const nextRequest = new Request(request);
  nextRequest.headers.set("x-custom-header", "custom-header-value");

  return nextRequest;
});

const novu = new Novu({
  httpClient,
  secretKey: "SECRET_KEY_VALUE",
  serverURL: "https://eu.api.novu.co",
});

novu.trigger({
  workflowId: "WORKFLOW_ID_VALUE",
  to: {
    subscriberId: "subscriberId",
  },
  payload: {
    message: "Hello, world!",
  },
});
```
