> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usesend.com/llms.txt
> Use this file to discover all available pages before exploring further.

# NodeJS

> Send your mail using useSend in NodeJS

## Prerequisites

* [useSend API key](https://app.usesend.com/dev-settings/api-keys)
* [Verified domain](https://app.usesend.com/domains)

## Using SDK

**1. Install SDK**

```bash npm theme={null}
npm install usesend-js
```

```bash yarn theme={null}
yarn add usesend-js
```

```bash pnpm theme={null}
pnpm add usesend-js
```

```bash bun theme={null}
bun add usesend-js
```

**2. Initialize SDK**

Get the API key from the [useSend dashboard](https://app.usesend.com/dev-settings/api-keys) and initialize the SDK

```javascript theme={null}
import { UseSend } from "usesend-js";

const usesend = new UseSend("us_12345");
```

If you are running a self-hosted version of useSend, pass the base URL as the
second argument:

```javascript theme={null}
const usesend = new UseSend("us_12345", "https://app.usesend.com");
```

**3. Send Email**

```javascript theme={null}
usesend.emails.send({
  to: "hello@acme.com",
  from: "hello@company.com",
  subject: "useSend email",
  html: "<p>useSend is the best open source product to send emails</p>",
  text: "useSend is the best open source product to send emails",
  headers: {
    "X-Campaign": "welcome",
  },
});
```

> Custom headers are forwarded as-is. useSend only manages the `X-Usesend-Email-ID` and `References` headers.

## Adding contacts programatically

**1. Get the contact book id**

Get the contact book id from the [useSend dashboard](https://app.usesend.com/contacts/). Copy the contact book id

**2. Add contacts**

```javascript theme={null}
usesend.contacts
  .create("clzeydgeygff", {
    email: "hey@koushik.dev",
    firstName: "Koushik",
    lastName: "KM",
  })
```

**3. Update contact**

```javascript theme={null}
usesend.contacts.update("clzeydgeygff", contactId, {
  firstName: "Koushik",
  lastName: "KM",
});
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.