---
title: NodeJS
description: "Send your mail using useSend in NodeJS"
icon: node-js
---

## Prerequisites

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

## Using SDK

<Steps>
  <Step title="Install SDK">
    <CodeGroup>
      ```bash npm
      npm install usesend-js
      ```

      ```bash yarn
      yarn add usesend-js
      ```

      ```bash pnpm
      pnpm add usesend-js
      ```

      ```bash bun
      bun add usesend-js
      ```
    </CodeGroup>

  </Step>
  <Step title="Initialize SDK">
    Get the API key from the [useSend dashboard](https://app.usesend.com/dev-settings/api-keys) and initialize the SDK

    ```javascript
    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
    const usesend = new UseSend("us_12345", "https://app.usesend.com");
    ```

  </Step>
  <Step title="Send Email">
    ```javascript
    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.
  </Step>
</Steps>

## Adding contacts programatically

<Steps>
  <Step title="Get the contact book id">
    Get the contact book id from the [useSend dashboard](https://app.usesend.com/contacts/). Copy the contact book id
  </Step>
  <Step title="Add contacts">

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

  </Step>

  <Step title="Update contact">
    ```javascript
    usesend.contacts.update("clzeydgeygff", contactId, {
      firstName: "Koushik",
      lastName: "KM",
    });
    ```
  </Step>
</Steps>
