apps/docs/content/docs/orm/prisma-client/deployment/traditional/deploy-to-render.mdx
This guide explains how to deploy a Node.js server that uses Prisma ORM and PostgreSQL to Render.
<details> <summary>Questions answered in this page</summary>The Prisma Render deployment example 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.
Render is a cloud application platform that lets developers easily deploy and scale full-stack applications. For this example, it's helpful to know:
Download the example code 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
Before we deploy the app, let's take a look at the example code.
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.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.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.The render.yaml file is a Render blueprint. 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:
The format of this file follows the Blueprint specification.
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.
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 |
| 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 |
That’s it. Your web service will be live at its onrender.com URL as soon as the build finishes.
You can also deploy the example using the Render Blueprint. Follow Render's [Blueprint setup guide] and use the render.yaml in the example.
Prisma ORM includes a framework for seeding the database 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:
If you manually deployed your Render services:
npx prisma migrate deploy; npx prisma db seedIf you deployed your Render services using the Blueprint:
render.yaml file, change the preDeployCommand to: npx prisma migrate deploy; npx prisma db seedRender allows you to SSH into your web service.
npx prisma db seed