# Deploy to Render

This guide explains how to deploy a Node.js server that uses Prisma ORM and PostgreSQL to Render.

:::accordion{title="Questions answered in this page"}
- How to deploy Prisma apps on Render?
- How to run migrations before start?
- What Render settings are recommended?
:::

The [Prisma Render deployment example](https://github.com/prisma/prisma-examples/tree/latest/deployment-platforms/render) contains an Express.js application with REST endpoints and a simple frontend. This app uses Prisma Client to fetch, create, and delete records from its database.

## [About Render](#about-render)

[Render](https://render.com/) is a cloud application platform for deploying and scaling full-stack applications. For this example, it's helpful to know:

- Render lets you deploy long-running, "serverful" full-stack applications. You can configure Render services to [autoscale](https://docs.render.com/scaling) based on CPU and/or memory usage. This is one of several [deployment paradigms](/guides/prisma-client-v7-deployment-deploy-prisma) you can choose from.
- Render natively supports [common runtimes](https://docs.render.com/language-support), including Node.js and Bun. In this guide, we'll use the Node.js runtime.
- Render [integrates with Git repos](https://docs.render.com/github) for automatic deployments upon commits. You can deploy to Render from GitHub, GitLab, or Bitbucket. In this guide, we'll deploy from a Git repository.

## [Prerequisites](#prerequisites)

- Sign up for a [Render](https://render.com/) account

## [Get the example code](#get-the-example-code)

Download the [example code](https://github.com/prisma/prisma-examples/tree/latest/deployment-platforms/render) to your local machine.

```
curl https://codeload.github.com/prisma/prisma-examples/tar.gz/latest | tar -xz --strip=2 prisma-examples-latest/deployment-platforms/render
cd render
```

## [Understand the example](#understand-the-example)

Before deploying, review the example code.

### [Web application](#web-application)

The logic for the Express app is in two files:

- `src/index.js`: The API. The endpoints use Prisma Client to fetch, create, and delete data from the database.
- `public/index.html`: The web frontend. The frontend calls a few of the API endpoints.

### [Prisma schema and migrations](#prisma-schema-and-migrations)

The Prisma components of this app are in two files:

- `prisma/schema.prisma`: The data model of this app. This example defines two models, `User` and `Post`. The format of this file follows the [Prisma schema](/guides/prisma-schema-v7-overview).
- `prisma/migrations/<migration name>/migration.sql`: The SQL commands that construct this schema in a PostgreSQL database. You can auto-generate migration files like this one by running [`prisma migrate dev`](/guides/prisma-migrate-v7-understanding-prisma-migrate-mental-model#what-is-prisma-migrate).

### [Render Blueprint](#render-blueprint)

The `render.yaml` file is a [Render blueprint](https://docs.render.com/infrastructure-as-code). Blueprints are Render's Infrastructure as Code format. You can use a Blueprint to programmatically create and modify services on Render.

A `render.yaml` defines the services that will be spun up on Render by a Blueprint. In this `render.yaml`, we see:

- **A web service that uses a Node runtime**: This is the Express app.
- **A PostgreSQL database**: This is the database that the Express app uses.

The format of this file follows the [Blueprint specification](https://docs.render.com/blueprint-spec).

### [How Render deploys work with Prisma Migrate](#how-render-deploys-work-with-prisma-migrate)

In general, you want all your database migrations to run before your web app is started. Otherwise, the app may hit errors when it queries a database that doesn't have the expected tables and rows.

You can use the Pre-Deploy Command setting in a Render deploy to run any commands, such as database migrations, before the app is started.

For more details about the Pre-Deploy Command, see [Render's deploy guide](https://docs.render.com/deploys#deploy-steps).

In our example code, the `render.yaml` shows the web service's build command, pre-deploy command, and start command. Notably, `npx prisma migrate deploy` (the pre-deploy command) will run before `npm run start` (the start command).

| **Command**        | **Value**                        |
| ------------------ | -------------------------------- |
| Build Command      | `npm install --production=false` |
| Pre-Deploy Command | `npx prisma migrate deploy`      |
| Start Command      | `npm run start`                  |

## [Deploy the example](#deploy-the-example)

### [1. Initialize your Git repository](#1-initialize-your-git-repository)

1. Download [the example code](https://github.com/prisma/prisma-examples/tree/latest/deployment-platforms/render) to your local machine.
2. Create a new Git repository on GitHub, GitLab, or BitBucket.
3. Upload the example code to your new repository.

### [2. Deploy manually](#2-deploy-manually)

1. In the Render Dashboard, click **New** > **PostgreSQL**. Provide a database name, and select a plan. (The Free plan works for this demo.)
2. After your database is ready, look up its [internal URL](https://docs.render.com/postgresql-creating-connecting#internal-connections).
3. In the Render Dashboard, click **New** > **Web Service** and connect the Git repository that contains the example code.
4. Provide the following values during service creation:

| **Setting**                                                  | **Value**                                              |
| ------------------------------------------------------------ | ------------------------------------------------------ |
| Language                                                     | `Node`                                                 |
| Build Command                                                | `npm install --production=false`                       |
| Pre-Deploy Command (Note: this may be in the "Advanced" tab) | `npx prisma migrate deploy`                            |
| Start Command                                                | `npm run start`                                        |
| Environment Variables                                        | Set `DATABASE_URL` to the internal URL of the database |

Your web service will be live at its `onrender.com` URL as soon as the build finishes.

### [3. (optional) Deploy with Infrastructure as Code](#3-optional-deploy-with-infrastructure-as-code)

You can also deploy the example using the Render Blueprint. Follow Render's [Blueprint setup guide](https://render.com/docs/infrastructure-as-code#setup) and use the `render.yaml` in the example.

## [Bonus: Seed the database](#bonus-seed-the-database)

Prisma ORM includes a framework for [seeding the database](/guides/prisma-migrate-v7-workflows-seeding) with starter data. In our example, `prisma/seed.js` defines some test users and posts.

To add these users to the database, we can either:

1. Add the seed script to our Pre-Deploy Command, or
2. Manually run the command on our server via an SSH shell

### [Method 1: Pre-Deploy Command](#method-1-pre-deploy-command)

If you manually deployed your Render services:

1. In the Render dashboard, navigate to your web service.
2. Select **Settings**.
3. Set the Pre-Deploy Command to: `npx prisma migrate deploy; npx prisma db seed`

If you deployed your Render services using the Blueprint:

1. In your `render.yaml` file, change the `preDeployCommand` to: `npx prisma migrate deploy; npx prisma db seed`
2. Commit the change to your Git repo.

### [Method 2: SSH](#method-2-ssh)

Render allows you to SSH into your web service.

1. Follow [Render's SSH guide](https://docs.render.com/ssh) to connect to your server.
2. In the shell, run: `npx prisma db seed`

## Related pages

- [Authentication & Tools](./authentication-tools-index.md)
- [Build](./build-index.md)
- [Changelog](../changelog.md)
- [Concepts](./concepts-index.md)
- [Console commands](./console-commands-index.md)
- [Contract Authoring](./contract-authoring-index.md)
- [Core Concepts](./core-concepts-index.md)
- [Data Modeling](./data-modeling-index.md)
- [Database](./database-index.md)
- [DB commands](./db-commands-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
