> ## Documentation Index
> Fetch the complete documentation index at: https://flatfileinc-feat-updatereactquickstart.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploying to Flatfile

> Learn how to deploy your code to Flatfile.

<Snippet file="shared/dxpbanner.mdx" />

For a production deployment, listeners can be hosted either in your cloud or directly on the Flatfile platform.

## Hosting on the Flatfile platform (recommended)

While your own cloud provides the maximum level of control over listener code, qualities such as availability and network performance are the responsibility of the hosting provider. Listeners may be securely deployed and run in the Flatfile platform cloud giving you a more consistent, low-latency, high-availability experience.

### Deploying a Workbook to Flatfile from terminal

Once you have configured your Workbook, you can deploy your Workbook to your account at any time
by opening the terminal in the root directory and entering this command:

<Warning>
  Add the file name to the command: `npx flatfile deploy path-to-file` if you're
  not running an index file.
</Warning>

<CodeGroup>
  ```npm terminal
  npx flatfile@latest deploy --token=YOUR_SECRET_KEY
  ```

  ```npm .env (optional)
  # --token isn't required in deploy command if your secret key is in a .env file
  FLATFILE_API_KEY="sk_****"
  ```
</CodeGroup>

The CLI will give you prompts and updates as it's deploying:

```terminal
> npx flatfile@latest deploy --token=sk_123456

✔  Code package compiled to .flatfile/build.js
✔  Code package passed validation
✔  Environment "Default" selected
✔  Event listener deployed and running on your environment "Default". us_ag_1234
```

#### See it in your Dashboard

Once your Workbook has been deployed, you’ll be able to see a new Space in your [Dashboard](https://platform.flatfile.com). Your Workbook will be added to every Space you create.

<Note>
  You can also configure your code to build different Workbooks as a Space is
  created depending on various factors. Learn about [Dynamic
  Configurations](../guides/dynamic-configurations.mdx).
</Note>

### Deploying more than once

You can deploy any change to your code at any time.

For example, if you need to add a Sheet to an already existing Workbook, simply deploy again with the added Sheet and everything will update.

## Hosting on Regional Servers

Regional servers are available upon request for those needing to host their applications closer to their user base, ensuring faster access and compliance with local data regulations. To deploy on a regional server, please contact our support team.

### URL References

| Region | URL                                                                    | API URL                                                                      | SPACE URL                                                              |
| ------ | ---------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| UK     | [https://platform.uk.flatfile.com/](https://platform.uk.flatfile.com/) | [https://platform.uk.flatfile.com/api](https://platform.uk.flatfile.com/api) | [https://platform.uk.flatfile.com/](https://platform.uk.flatfile.com/) |
| EU     | [https://platform.eu.flatfile.com/](https://platform.eu.flatfile.com/) | [https://platform.eu.flatfile.com/api](https://platform.eu.flatfile.com/api) | [https://platform.eu.flatfile.com/](https://platform.eu.flatfile.com/) |
| AU     | [https://platform.au.flatfile.com/](https://platform.au.flatfile.com/) | [https://platform.au.flatfile.com/api](https://platform.au.flatfile.com/api) | [https://platform.au.flatfile.com/](https://platform.au.flatfile.com/) |
| CA     | [https://platform.ca.flatfile.com/](https://platform.ca.flatfile.com/) | [https://platform.ca.flatfile.com/api](https://platform.ca.flatfile.com/api) | [https://platform.ca.flatfile.com/](https://platform.ca.flatfile.com/) |

### Configuring the API URL for Deployment

When deploying, you can specify the `FLATFILE_API_URL` either in your project's `.env` file or as an environment variable.

<CodeGroup>
  ```sh Deploy command example
  npx flatfile@latest deploy
  ```

  ```npm .env file example (optional)
  FLATFILE_API_KEY="sk_****"
  FLATFILE_API_URL="Your Regional API URL here"
  ```
</CodeGroup>

### Embedding with a Specific API URL

To embed Flatfile in your application, include both apiUrl and spaceUrl in your FlatfileImporter configuration to specify your regional server:

```typescript
const spaceProps: ISpace = {
  name: "Embedded Space",
  publishableKey: "pk_**********",
  apiUrl: "Regional API URL here",
  spaceUrl: "Regional Space URL here", //Optional, only needed if reusing a space
  workbook,
  listener,
  // Additional properties here
};
```

### API Interaction with a Specified Environment

For direct API interactions, the FlatfileClient needs the environment parameter set to your selected regional API URL:

```ts
import { FlatfileClient } from "@flatfile/api";

const api = new FlatfileClient({
  environment: "Regional API URL here",
});
```

## Hosting in your own cloud

Hosting listener code in your own cloud works similarly to how we run the `develop` command in that:

1. The listener process is launched
2. It polls the Flatfile API for updates
3. It then responds to those Events accordingly

Reach out to support for learning how about hosting in your own cloud.
