# Deploy to Cloudflare Workers & Pages (/docs/orm/prisma-client/deployment/edge/deploy-to-cloudflare)

Location: ORM > Prisma Client > Deployment > Edge > Deploy to Cloudflare Workers & Pages

> [!NOTE]
> Quick summary
> 
> This page covers everything you need to know to deploy an app with Prisma ORM to a [Cloudflare Worker](https://developers.cloudflare.com/workers/) or to [Cloudflare Pages](https://developers.cloudflare.com/pages).

<details>
  <summary>
    Questions answered in this page
  </summary>

  * How to deploy Prisma to Cloudflare Workers?
  * Which drivers work on Workers/Pages?
  * How to configure DATABASE\_URL and envs?
</details>

General considerations when deploying to Cloudflare Workers [#general-considerations-when-deploying-to-cloudflare-workers]

This section covers *general* things you need to be aware of when deploying to Cloudflare Workers or Pages and are using Prisma ORM, regardless of the database provider you use.

Using Prisma Postgres [#using-prisma-postgres]

You can use Prisma Postgres and deploy to Cloudflare Workers.

After you create a Worker, run:

  

#### npm

```bash
npx prisma@latest init --db
```

#### pnpm

```bash
pnpm dlx prisma@latest init --db
```

#### yarn

```bash
yarn dlx prisma@latest init --db
```

#### bun

```bash
bunx --bun prisma@latest init --db
```

Enter a name for your project and choose a database region.

This command:

* Connects your CLI to your [Prisma Data Platform](https://console.prisma.io/?utm_source=docs\&utm_medium=content\&utm_content=orm) account. If you're not logged in or don't have an account, your browser will open to guide you through creating a new account or signing into your existing one.
* Creates a `prisma` directory containing a `schema.prisma` file for your database models.
* Creates a `.env` file with your `DATABASE_URL`.

Using an edge-compatible driver [#using-an-edge-compatible-driver]

When deploying a Cloudflare Worker that uses Prisma ORM, you need to use an [edge-compatible driver](/orm/prisma-client/deployment/edge/overview#edge-compatibility-of-database-drivers) and its respective [driver adapter](/orm/core-concepts/supported-databases/database-drivers#driver-adapters) for Prisma ORM.

The edge-compatible drivers for Cloudflare Workers and Pages are:

* [Neon Serverless](https://neon.tech/docs/serverless/serverless-driver) uses HTTP to access the database
* [PlanetScale Serverless](https://planetscale.com/docs/tutorials/planetscale-serverless-driver) uses HTTP to access the database
* [`node-postgres`](https://node-postgres.com/) (`pg`) uses Cloudflare's `connect()` (TCP) to access the database
* [`@libsql/client`](https://github.com/tursodatabase/libsql-client-ts) is used to access Turso databases via HTTP
* [Cloudflare D1](/orm/prisma-client/deployment/edge/deploy-to-cloudflare) is used to access D1 databases

There's [also work being done](https://github.com/sidorares/node-mysql2/pull/2289) on the `node-mysql2` driver which will enable access to traditional MySQL databases from Cloudflare Workers and Pages in the future as well.

If your application uses PostgreSQL, we recommend using [Prisma Postgres](/postgres). It is fully supported on edge runtimes and does not require a specialized edge-compatible driver. Review the [Prisma Postgres serverless driver limitations](/postgres/database/serverless-driver#limitations) to understand current constraints.

Setting your database connection URL as an environment variable [#setting-your-database-connection-url-as-an-environment-variable]

First, ensure that your `datasource` block in your Prisma schema is configured correctly. Database connection URLs are configured in `prisma.config.ts`:

```prisma
datasource db {
  provider = "postgresql" // this might also be `mysql` or another value depending on your database
}
```

```ts title="prisma.config.ts"
import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  datasource: {
    url: env("DATABASE_URL"),
  },
});
```

Development [#development]

When using your Worker in **development**, you can configure your database connection via the [`.dev.vars` file](https://developers.cloudflare.com/workers/configuration/secrets/#local-development-with-secrets) locally.

Assuming you use the `DATABASE_URL` environment variable from above, you can set it inside `.dev.vars` as follows:

```bash title=".dev.vars"
DATABASE_URL="your-database-connection-string"
```

In the above snippet, `your-database-connection-string` is a placeholder that you need to replace with the value of your own connection string, for example:

```bash title=".dev.vars"
DATABASE_URL="postgresql://admin:mypassword42@somehost.aws.com:5432/mydb"
```

Note that the `.dev.vars` file is not compatible with `.env` files which are typically used by Prisma ORM.

This means that you need to make sure that Prisma ORM gets access to the environment variable when needed, e.g. when running a Prisma CLI command like `prisma migrate dev`.

There are several options for achieving this:

* Run your Prisma CLI commands using [`dotenv`](https://www.npmjs.com/package/dotenv-cli) to specify from where the CLI should read the environment variable, for example:
  ```bash
  dotenv -e .dev.vars -- npx prisma migrate dev
  ```
* Create a script in `package.json` that reads `.dev.vars` via [`dotenv`](https://www.npmjs.com/package/dotenv-cli). You can then execute `prisma` commands as follows: `npm run env -- npx prisma migrate dev`. Here's a reference for the script:
  ```js title="package.json"
  "scripts":  { "env": "dotenv -e .dev.vars" }
  ```
* Duplicate the `DATABASE_URL` and any other relevant env vars into a new file called `.env` which can then be used by Prisma ORM.

> [!NOTE]
> If you're using an approach that requires `dotenv`, you need to have the [`dotenv-cli`](https://www.npmjs.com/package/dotenv-cli) package installed. You can do this e.g. by using this command to install the package locally in your project: `npm install -D dotenv-cli`.

Production [#production]

When deploying your Worker to **production**, you'll need to set the database connection using the `wrangler` CLI:

  

#### npm

```bash
npx wrangler secret put DATABASE_URL
```

#### pnpm

```bash
pnpm dlx wrangler secret put DATABASE_URL
```

#### yarn

```bash
yarn dlx wrangler secret put DATABASE_URL
```

#### bun

```bash
bunx --bun wrangler secret put DATABASE_URL
```

The command is interactive and will ask you to enter the value for the `DATABASE_URL` env var as the next step in the terminal.

> [!NOTE]
> This command requires you to be authenticated, and will ask you to log in to your Cloudflare account in case you are not.

Size limits on free accounts [#size-limits-on-free-accounts]

Cloudflare has a [size limit of 3 MB for Workers on the free plan](https://developers.cloudflare.com/workers/platform/limits/). If your application bundle with Prisma ORM exceeds that size, we recommend upgrading to a paid Worker plan.

Deploying a Next.js app to Cloudflare Pages with @cloudflare/next-on-pages [#deploying-a-nextjs-app-to-cloudflare-pages-with-cloudflarenext-on-pages]

Cloudflare offers an option to run Next.js apps on Cloudflare Pages with [`@cloudflare/next-on-pages`](https://github.com/cloudflare/next-on-pages), see the [docs](https://developers.cloudflare.com/pages/framework-guides/nextjs/ssr/get-started/) for instructions.

Based on some testing, we found the following:

* You can deploy using the PlanetScale or Neon Serverless Driver.
* Traditional PostgreSQL deployments using `pg` don't work because `pg` itself currently does not work with `@cloudflare/next-on-pages` (see [here](https://github.com/cloudflare/next-on-pages/issues/605)).

Feel free to reach out to us on [Discord](https://pris.ly/discord?utm_source=docs\&utm_medium=inline_text) if you find that anything has changed about this.

Database-specific considerations & examples [#database-specific-considerations--examples]

This section provides database-specific instructions for deploying a Cloudflare Worker with Prisma ORM.

Prerequisites [#prerequisites]

As a prerequisite for the following section, you need to have a Cloudflare Worker running locally and the Prisma CLI installed.

If you don't have that yet, you can run these commands:

  

#### npm

```bash
npm create cloudflare@latest prisma-cloudflare-worker-example -- --type hello-world
cd prisma-cloudflare-worker-example
npm install prisma --save-dev && npm install @prisma/client
npx prisma init --output ../generated/prisma
```

#### pnpm

```bash
pnpm create cloudflare prisma-cloudflare-worker-example --type hello-world
cd prisma-cloudflare-worker-example
pnpm add prisma --save-dev&& pnpm add @prisma/client
pnpm dlx prisma init --output ../generated/prisma
```

#### yarn

```bash
yarn create cloudflare prisma-cloudflare-worker-example --type hello-world
cd prisma-cloudflare-worker-example
yarn add prisma --dev&& yarn add @prisma/client
yarn dlx prisma init --output ../generated/prisma
```

#### bun

```bash
bunx create-cloudflare prisma-cloudflare-worker-example --type hello-world
cd prisma-cloudflare-worker-example
bun add prisma --dev&& bun add @prisma/client
bun x prisma init --output ../generated/prisma
```

You'll further need a database instance of your database provider of choice available. Refer to the respective documentation of the provider for setting up that instance.

We'll use the default `User` model for the example below:

```prisma
model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
}
```

PostgreSQL (traditional) [#postgresql-traditional]

If you are using a traditional PostgreSQL database that's accessed via TCP and the `pg` driver, you need to:

* use the `@prisma/adapter-pg` database adapter (learn more [here](/orm/core-concepts/supported-databases/postgresql#using-driver-adapters))
* set `node_compat = true` in `wrangler.toml` (see the [Cloudflare docs](https://developers.cloudflare.com/workers/runtime-apis/nodejs/))

1. Configure Prisma schema & database connection [#1-configure-prisma-schema--database-connection]

> [!NOTE]
> If you don't have a project to deploy, follow the instructions in the [Prerequisites](#prerequisites) to bootstrap a basic Cloudflare Worker with Prisma ORM in it.

First, ensure that the database connection is configured properly. Database connection URLs are configured in `prisma.config.ts`:

```prisma title="schema.prisma"
generator client {
  provider = "prisma-client"
  output   = "./generated"
}

datasource db {
  provider = "postgresql"
}
```

```ts title="prisma.config.ts"
import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  datasource: {
    url: env("DATABASE_URL"),
  },
});
```

Next, you need to set the `DATABASE_URL` environment variable to the value of your database connection string. You'll do this in a file called `.dev.vars` used by Cloudflare:

```bash title=".dev.vars"
DATABASE_URL="postgresql://admin:mypassword42@somehost.aws.com:5432/mydb"
```

Because the Prisma CLI by default is only compatible with `.env` files, you can adjust your `package.json` with the following script that loads the env vars from `.dev.vars`. You can then use this script to load the env vars before executing a `prisma` command.

Add this script to your `package.json`:

```js title="package.json" highlight=5;add
{
  // ...
  "scripts": {
    // ....
    "env": "dotenv -e .dev.vars"
  },
  // ...
}
```

Now you can execute Prisma CLI commands as follows while ensuring that the command has access to the env vars in `.dev.vars`:

  

#### npm

```bash
npm run env -- npx prisma
```

#### pnpm

```bash
npm run env -- pnpm dlx prisma
```

#### yarn

```bash
npm run env -- yarn dlx prisma
```

#### bun

```bash
npm run env -- bun x prisma
```

2. Install dependencies [#2-install-dependencies]

Next, install the required packages:

  

#### npm

```bash
npm install @prisma/adapter-pg
```

#### pnpm

```bash
pnpm add @prisma/adapter-pg
```

#### yarn

```bash
yarn add @prisma/adapter-pg
```

#### bun

```bash
bun add @prisma/adapter-pg
```

3. Set node_compat = true in wrangler.toml [#3-set-node_compat--true-in-wranglertoml]

In your `wrangler.toml` file, add the following line:

```toml title="wrangler.toml"
node_compat = true
```

> [!NOTE]
> For Cloudflare Pages, using `node_compat` is not officially supported. If you want to use `pg` in Cloudflare Pages, you can find a workaround [here](https://github.com/cloudflare/workers-sdk/pull/2541#issuecomment-1954209855).

4. Migrate your database schema (if applicable) [#4-migrate-your-database-schema-if-applicable]

If you ran `npx prisma init` above, you need to migrate your database schema to create the `User` table that's defined in your Prisma schema (if you already have all the tables you need in your database, you can skip this step):

  

#### npm

```bash
npm run env -- npx prisma migrate dev --name init
```

#### pnpm

```bash
npm run env -- pnpm dlx prisma migrate dev --name init
```

#### yarn

```bash
npm run env -- yarn dlx prisma migrate dev --name init
```

#### bun

```bash
npm run env -- bun x prisma migrate dev --name init
```

5. Use Prisma Client in your Worker to send a query to the database [#5-use-prisma-client-in-your-worker-to-send-a-query-to-the-database]

Here is a sample code snippet that you can use to instantiate `PrismaClient` and send a query to your database:

```ts
import { PrismaClient } from "./generated/client";
import { PrismaPg } from "@prisma/adapter-pg";

export default {
  async fetch(request, env, ctx) {
    const adapter = new PrismaPg({ connectionString: env.DATABASE_URL });
    const prisma = new PrismaClient({ adapter });

    const users = await prisma.user.findMany();
    const result = JSON.stringify(users);
    ctx.waitUntil(prisma.$disconnect());
    return new Response(result);
  },
};
```

6. Run the Worker locally [#6-run-the-worker-locally]

To run the Worker locally, you can run the `wrangler dev` command:

  

#### npm

```bash
npx wrangler dev
```

#### pnpm

```bash
pnpm dlx wrangler dev
```

#### yarn

```bash
yarn dlx wrangler dev
```

#### bun

```bash
bunx --bun wrangler dev
```

7. Set the DATABASE_URL environment variable and deploy the Worker [#7-set-the-database_url-environment-variable-and-deploy-the-worker]

To deploy the Worker, you first need to the `DATABASE_URL` environment variable [via the `wrangler` CLI](https://developers.cloudflare.com/workers/configuration/secrets/#secrets-on-deployed-workers):

  

#### npm

```bash
npx wrangler secret put DATABASE_URL
```

#### pnpm

```bash
pnpm dlx wrangler secret put DATABASE_URL
```

#### yarn

```bash
yarn dlx wrangler secret put DATABASE_URL
```

#### bun

```bash
bunx --bun wrangler secret put DATABASE_URL
```

The command is interactive and will ask you to enter the value for the `DATABASE_URL` env var as the next step in the terminal.

> [!NOTE]
> This command requires you to be authenticated, and will ask you to log in to your Cloudflare account in case you are not.

Then you can go ahead then deploy the Worker:

  

#### npm

```bash
npx wrangler deploy
```

#### pnpm

```bash
pnpm dlx wrangler deploy
```

#### yarn

```bash
yarn dlx wrangler deploy
```

#### bun

```bash
bunx --bun wrangler deploy
```

The command will output the URL where you can access the deployed Worker.

PlanetScale [#planetscale]

If you are using a PlanetScale database, you need to:

* use the `@prisma/adapter-planetscale` database adapter (learn more [here](/orm/core-concepts/supported-databases/mysql#planetscale))
* manually remove the conflicting `cache` field:

  ```ts
  export default {
    async fetch(request, env, ctx) {
      const adapter = new PrismaPlanetScale({
        url: env.DATABASE_URL,
        // see https://github.com/cloudflare/workerd/issues/698
        fetch(url, init) {
          delete init["cache"];
          return fetch(url, init);
        },
      });
      const prisma = new PrismaClient({ adapter });

      // ...
    },
  };
  ```

1. Configure Prisma schema & database connection [#1-configure-prisma-schema--database-connection-1]

> [!NOTE]
> If you don't have a project to deploy, follow the instructions in the [Prerequisites](#prerequisites) to bootstrap a basic Cloudflare Worker with Prisma ORM in it.

First, ensure that the database connection is configured properly. Database connection URLs are configured in `prisma.config.ts`:

```prisma title="schema.prisma"
generator client {
  provider = "prisma-client"
  output   = "./generated"
}

datasource db {
  provider     = "mysql"
  relationMode = "prisma" // required for PlanetScale (as by default foreign keys are disabled)
}
```

```ts title="prisma.config.ts"
import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  datasource: {
    url: env("DATABASE_URL"),
  },
});
```

Next, you need to set the `DATABASE_URL` environment variable to the value of your database connection string. You'll do this in a file called `.dev.vars` used by Cloudflare:

```bash title=".dev.vars"
DATABASE_URL="mysql://32qxa2r7hfl3102wrccj:password@us-east.connect.psdb.cloud/demo-cf-worker-ps?sslaccept=strict"
```

Because the Prisma CLI by default is only compatible with `.env` files, you can adjust your `package.json` with the following script that loads the env vars from `.dev.vars`. You can then use this script to load the env vars before executing a `prisma` command.

Add this script to your `package.json`:

```js title="package.json" highlight=5;add
{
  // ...
  "scripts": {
    // ....
    "env": "dotenv -e .dev.vars"
  },
  // ...
}
```

Now you can execute Prisma CLI commands as follows while ensuring that the command has access to the env vars in `.dev.vars`:

  

#### npm

```bash
npm run env -- npx prisma
```

#### pnpm

```bash
npm run env -- pnpm dlx prisma
```

#### yarn

```bash
npm run env -- yarn dlx prisma
```

#### bun

```bash
npm run env -- bun x prisma
```

2. Install dependencies [#2-install-dependencies-1]

Next, install the required packages:

  

#### npm

```bash
npm install @prisma/adapter-planetscale
```

#### pnpm

```bash
pnpm add @prisma/adapter-planetscale
```

#### yarn

```bash
yarn add @prisma/adapter-planetscale
```

#### bun

```bash
bun add @prisma/adapter-planetscale
```

3. Migrate your database schema (if applicable) [#3-migrate-your-database-schema-if-applicable]

If you ran `npx prisma init` above, you need to migrate your database schema to create the `User` table that's defined in your Prisma schema (if you already have all the tables you need in your database, you can skip this step):

  

#### npm

```bash
npm run env -- npx prisma db push
```

#### pnpm

```bash
npm run env -- pnpm dlx prisma db push
```

#### yarn

```bash
npm run env -- yarn dlx prisma db push
```

#### bun

```bash
npm run env -- bun x prisma db push
```

4. Use Prisma Client in your Worker to send a query to the database [#4-use-prisma-client-in-your-worker-to-send-a-query-to-the-database]

Here is a sample code snippet that you can use to instantiate `PrismaClient` and send a query to your database:

```ts
import { PrismaClient } from "./generated/client";
import { PrismaPlanetScale } from "@prisma/adapter-planetscale";

export default {
  async fetch(request, env, ctx) {
    const adapter = new PrismaPlanetScale({
      url: env.DATABASE_URL,
      // see https://github.com/cloudflare/workerd/issues/698
      fetch(url, init) {
        delete init["cache"];
        return fetch(url, init);
      },
    });
    const prisma = new PrismaClient({ adapter });

    const users = await prisma.user.findMany();
    const result = JSON.stringify(users);
    ctx.waitUntil(prisma.$disconnect());
    return new Response(result);
  },
};
```

6. Run the Worker locally [#6-run-the-worker-locally-1]

To run the Worker locally, you can run the `wrangler dev` command:

  

#### npm

```bash
npx wrangler dev
```

#### pnpm

```bash
pnpm dlx wrangler dev
```

#### yarn

```bash
yarn dlx wrangler dev
```

#### bun

```bash
bunx --bun wrangler dev
```

7. Set the DATABASE_URL environment variable and deploy the Worker [#7-set-the-database_url-environment-variable-and-deploy-the-worker-1]

To deploy the Worker, you first need to the `DATABASE_URL` environment variable [via the `wrangler` CLI](https://developers.cloudflare.com/workers/configuration/secrets/#secrets-on-deployed-workers):

  

#### npm

```bash
npx wrangler secret put DATABASE_URL
```

#### pnpm

```bash
pnpm dlx wrangler secret put DATABASE_URL
```

#### yarn

```bash
yarn dlx wrangler secret put DATABASE_URL
```

#### bun

```bash
bunx --bun wrangler secret put DATABASE_URL
```

The command is interactive and will ask you to enter the value for the `DATABASE_URL` env var as the next step in the terminal.

> [!NOTE]
> This command requires you to be authenticated, and will ask you to log in to your Cloudflare account in case you are not.

Then you can go ahead then deploy the Worker:

  

#### npm

```bash
npx wrangler deploy
```

#### pnpm

```bash
pnpm dlx wrangler deploy
```

#### yarn

```bash
yarn dlx wrangler deploy
```

#### bun

```bash
bunx --bun wrangler deploy
```

The command will output the URL where you can access the deployed Worker.

Neon [#neon]

If you are using a Neon database, you need to:

* use the `@prisma/adapter-neon` database adapter (learn more [here](/orm/core-concepts/supported-databases/postgresql#using-driver-adapters))

1. Configure Prisma schema & database connection [#1-configure-prisma-schema--database-connection-2]

> [!NOTE]
> If you don't have a project to deploy, follow the instructions in the [Prerequisites](#prerequisites) to bootstrap a basic Cloudflare Worker with Prisma ORM in it.

First, ensure that the database connection is configured properly. Database connection URLs are configured in `prisma.config.ts`:

```prisma title="schema.prisma"
generator client {
  provider = "prisma-client"
  output   = "./generated"
}

datasource db {
  provider = "postgresql"
}
```

```ts title="prisma.config.ts"
import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  datasource: {
    url: env("DATABASE_URL"),
  },
});
```

Next, you need to set the `DATABASE_URL` environment variable to the value of your database connection string. You'll do this in a file called `.dev.vars` used by Cloudflare:

```bash title=".dev.vars"
DATABASE_URL="postgresql://janedoe:password@ep-nameless-pond-a23b1mdz.eu-central-1.aws.neon.tech/neondb?sslmode=require"
```

Because the Prisma CLI by default is only compatible with `.env` files, you can adjust your `package.json` with the following script that loads the env vars from `.dev.vars`. You can then use this script to load the env vars before executing a `prisma` command.

Add this script to your `package.json`:

```js title="package.json" highlight=5;add
{
  // ...
  "scripts": {
    // ....
    "env": "dotenv -e .dev.vars"
  },
  // ...
}
```

Now you can execute Prisma CLI commands as follows while ensuring that the command has access to the env vars in `.dev.vars`:

  

#### npm

```bash
npm run env -- npx prisma
```

#### pnpm

```bash
npm run env -- pnpm dlx prisma
```

#### yarn

```bash
npm run env -- yarn dlx prisma
```

#### bun

```bash
npm run env -- bun x prisma
```

2. Install dependencies [#2-install-dependencies-2]

Next, install the required packages:

  

#### npm

```bash
npm install @prisma/adapter-neon
```

#### pnpm

```bash
pnpm add @prisma/adapter-neon
```

#### yarn

```bash
yarn add @prisma/adapter-neon
```

#### bun

```bash
bun add @prisma/adapter-neon
```

3. Migrate your database schema (if applicable) [#3-migrate-your-database-schema-if-applicable-1]

If you ran `npx prisma init` above, you need to migrate your database schema to create the `User` table that's defined in your Prisma schema (if you already have all the tables you need in your database, you can skip this step):

  

#### npm

```bash
npm run env -- npx prisma migrate dev --name init
```

#### pnpm

```bash
npm run env -- pnpm dlx prisma migrate dev --name init
```

#### yarn

```bash
npm run env -- yarn dlx prisma migrate dev --name init
```

#### bun

```bash
npm run env -- bun x prisma migrate dev --name init
```

5. Use Prisma Client in your Worker to send a query to the database [#5-use-prisma-client-in-your-worker-to-send-a-query-to-the-database-1]

Here is a sample code snippet that you can use to instantiate `PrismaClient` and send a query to your database:

```ts
import { PrismaClient } from "./generated/client";
import { PrismaNeon } from "@prisma/adapter-neon";

export default {
  async fetch(request, env, ctx) {
    const adapter = new PrismaNeon({ connectionString: env.DATABASE_URL });
    const prisma = new PrismaClient({ adapter });

    const users = await prisma.user.findMany();
    const result = JSON.stringify(users);
    ctx.waitUntil(prisma.$disconnect());
    return new Response(result);
  },
};
```

6. Run the Worker locally [#6-run-the-worker-locally-2]

To run the Worker locally, you can run the `wrangler dev` command:

  

#### npm

```bash
npx wrangler dev
```

#### pnpm

```bash
pnpm dlx wrangler dev
```

#### yarn

```bash
yarn dlx wrangler dev
```

#### bun

```bash
bunx --bun wrangler dev
```

7. Set the DATABASE_URL environment variable and deploy the Worker [#7-set-the-database_url-environment-variable-and-deploy-the-worker-2]

To deploy the Worker, you first need to the `DATABASE_URL` environment variable [via the `wrangler` CLI](https://developers.cloudflare.com/workers/configuration/secrets/#secrets-on-deployed-workers):

  

#### npm

```bash
npx wrangler secret put DATABASE_URL
```

#### pnpm

```bash
pnpm dlx wrangler secret put DATABASE_URL
```

#### yarn

```bash
yarn dlx wrangler secret put DATABASE_URL
```

#### bun

```bash
bunx --bun wrangler secret put DATABASE_URL
```

The command is interactive and will ask you to enter the value for the `DATABASE_URL` env var as the next step in the terminal.

> [!NOTE]
> This command requires you to be authenticated, and will ask you to log in to your Cloudflare account in case you are not.

Then you can go ahead then deploy the Worker:

  

#### npm

```bash
npx wrangler deploy
```

#### pnpm

```bash
pnpm dlx wrangler deploy
```

#### yarn

```bash
yarn dlx wrangler deploy
```

#### bun

```bash
bunx --bun wrangler deploy
```

The command will output the URL where you can access the deployed Worker.

Cloudflare D1 [#cloudflare-d1]

> [!NOTE]
> Using Cloudflare D1
> 
> For step-by-step instructions on using Prisma ORM with [Cloudflare D1](https://developers.cloudflare.com/d1/) (schema setup, migrations, and deploying your Worker), see the dedicated [Cloudflare D1 deployment guide](/guides/deployment/cloudflare-d1).

## Related pages

- [`Deploy to Deno Deploy`](https://www.prisma.io/docs/orm/prisma-client/deployment/edge/deploy-to-deno-deploy)
- [`Deploy to Vercel Edge Functions & Middleware`](https://www.prisma.io/docs/orm/prisma-client/deployment/edge/deploy-to-vercel): Learn the things you need to know in order to deploy an Edge function that uses Prisma Client for talking to a database
- [`Deploying edge functions with Prisma ORM`](https://www.prisma.io/docs/orm/prisma-client/deployment/edge/overview): Learn how to deploy your Prisma-backed apps to edge functions like Cloudflare Workers or Vercel Edge Functions