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

# Express

> Learn how to send and receive instant Bitcoin payments with Express and ZBD.

## Prerequisites

To complete this guide, you will need the following:

* [ZBD Project with a Live API key](/get-started/api-keys)

## 1. Create a Node.js project

Start with a brand new empty directory called `express-example` and run the following command to initiate a Node.js project:

```bash theme={null}
npm init -y
```

## 2. Install Express.js

Inside your project directory, run the following command to install Express.js:

<CodeGroup>
  ```bash yarn theme={null}
  yarn add express
  ```

  ```bash npm theme={null}
  npm install express
  ```

  ```bash pnpm theme={null}
  pnpm add express
  ```
</CodeGroup>

## 3. Install @zbdpay/payments-sdk Node.js SDK

Inside your Express.js

<CodeGroup>
  ```bash yarn theme={null}
  yarn add @zbdpay/payments-sdk
  ```

  ```bash npm theme={null}
  npm install @zbdpay/payments-sdk
  ```

  ```bash pnpm theme={null}
  pnpm add @zbdpay/payments-sdk
  ```
</CodeGroup>

## 4. Send and receive Bitcoin

Create a new file called `index.js` and add the following code:

```js theme={null}
import express from "express";
import ZbdPayments from '@zbdpay/payments-sdk';

const ZBD_API_KEY = 'b7YW3s2JzZKGcXjIf5Dqof8wjKT2RuWr8'; // dummy key
const client = new ZbdPayments({
  apikey: ZBD_API_KEY,
});

// Create Express app
const app = express();

// Creating a Bitcoin Lightning payment request
app.get("/request", async (req, res) => {
  try {
    const data = await client.lightningCharges.create({
      amount: '100000',
      callbackUrl: 'https://your-app.com/zbd-callback',
      description: 'Express + ZBD!',
    });
    res.status(200).json({ data });
  } catch (error) {
    res.status(500).json({ error });
  }
});

// Send a payment to a Bitcoin Lightning Address
app.get("/send", async (req, res) => {
  try {
    const data = await client.lightningAddress.sendPayment({
      lnAddress: "andreneves@zbd.gg", // Who is the recipient?
      amount: "100000", // 100 satoshis (100,000 msats)
      comment: "Express + ZBD!",
    });
    res.status(200).json({ data });
  } catch (error) {
    res.status(500).json({ error });
  }
});

app.listen(3000, () => {
  console.log("Express server w/ ZBD listening on https://example.com");
});
```

Run the following command to start your Express.js server:

<CodeGroup>
  ```bash yarn theme={null}
  yarn start
  ```

  ```bash npm theme={null}
  npm start
  ```
</CodeGroup>

Opening your browser to the following URL: `https://example.com/request` should return a JSON response with a payment request.

You can also test this using curl command:

```bash theme={null}
curl https://example.com/request
```

You're looking for the `data.invoice.request` property in the JSON response. It starts with `lnbc1` and is the payment request anyone in the Bitcoin Lightning Network can use to pay you.

```
lnbc1u1pjdlax9pp5t7jhkd7h2wntd4f2v7xp22dknmjxp0q8nm7hfcny4p7a5mr7x3rsdp9f4hkueteypshggrfde6x2unwv46zqumsv4jkgcqzzsxqzjcsp5dsayu6m6632p28rnkeeqsr7d54amrkv6wh46yrv42gdgca8xl8gs9qyyssqgj2zrkax733rzulfkzc5mqsr8fpwrva82stpa7e0frw32722trv37jlq8mvlqfp8y75lr6mz63zd7qnxar8hhsehuy22pvfq6wjxwqqqa60lx3
```

<Info>Charges and payment requests are usually shown to users as QR codes that can be scanned by mobile apps (e.g. [ZBD](https://zbd.one/download)). Read [Callbacks](/payments/api/callbacks) to understand how to receive updates about your payment asynchronously.</Info>

Opening your browser to the following URL: `https://example.com/send` should return a JSON response with the payment sent message.

You can also test this using curl command:

```bash theme={null}
curl https://example.com/send
```

You're looking for the `status` of `completed` to know that the payment settled successfully.

<Info>Payments in the Lightning Network are asynchronous so you may see a response stating the payment is `processing`. This is expected -- use the `callbackUrl` property to receive updates about your payments.</Info>

## 3. Try it yourself

You can now send and receive instant Bitcoin payments using Express.js + ZBD!

<CardGroup cols={1}>
  <Card title="Express.js Example" icon="github" color="#000000" href="https://github.com/zebedeeio/zbd-express-example">
    See the full source code.
  </Card>
</CardGroup>
