- Clone the repo
- Run
npm installin the root directory - Login or create a Neon account via the dashboard
- Create a new project
- Click
Connectand set the dropdown toPrismawithConnection poolingenabled - Copy the
DATABASE_URLandDIRECT_URLfrom the connection string - Create a
.envfile in theapps/my-next-apppackage and paste the connection strings:DATABASE_URL="postgresql://postgres:password@[url]-pooler.eu-west-2.aws.neon.tech/neondb?sslmode=require&channel_binding=require" DIRECT_URL="postgresql://postgres:password@[url].eu-west-2.aws.neon.tech/neondb?sslmode=require&channel_binding=require"
- Run
npm run db:seedin theprismapackage to seed the database - Run
npm run devin theapps/my-next-apppackage to start the Next.js app - Open your browser and navigate to
http://localhost:3000to validate the/api/testendpoint works - Stop the server and then run
npm run previewto start the preview server - Open your browser and navigate to
http://127.0.0.1:8787/api/testto validate the preview fails with the error:Error: [unenv] fs.readdir is not implemented yet!
-
Initialise a new Turborepo:
npx create-turbo@latest -
Delete all items in
appsandpackagesfolders
-
Application scaffolded in
appsfolder from OpenNext docs:npm create cloudflare@latest -- my-next-app --framework=next --platform=workers -
Run
npm run devinapps/my-next-appto validate that the Next.js app works -
Run
npm run previewto validate preview works
-
Create a
prismapackage inpackagesfolder -
Run
npm install prisma tsx --save-devin theprismapackage. Reference -
Run
npm install @prisma/client -
Run
npx prisma init -
Match my own file structure; move schema.prisma to
packages/prisma/schema/schema.prisma -
Add config to
package.jsonfor Prisma multi-file schema support:"prisma": { "schema": "./schema", "seed": "tsx ./seed/seed.ts" },
-
Split schema from Prisma example to two separate files:
packages/prisma/schema/user.schema.tspackages/prisma/schema/post.schema.ts
-
Update
prisma/schema/schema.prismato use Neon configuration:generator client { provider = "prisma-client-js" previewFeatures = ["driverAdapters"] } datasource db { provider = "postgresql" url = env("DATABASE_URL") directUrl = env("DIRECT_URL") }
-
Add
DATABASE_URLandDIRECT_URLto.envfile in theprismapackage:DATABASE_URL="postgresql://postgres:password@[url]-pooler.eu-west-2.aws.neon.tech/neondb?sslmode=require&channel_binding=require" DIRECT_URL="postgresql://postgres:password@[url].eu-west-2.aws.neon.tech/neondb?sslmode=require&channel_binding=require"
-
Run
npx prisma migrate dev --name init -
Run
npm run db:seed -
Run
npx prisma studioto validate that the Prisma client works and the database is seeded correctly -
Install
@prisma/adapter-neon -
Create
client.ts -
Create
index.ts
This section follows the OpenNext docs
- Add
serverExternalPackages: ["@prisma/client", ".prisma/client", "@prisma/adapter-neon"],tonext.config.ts - Create
lib/db.ts - Create
app/api/test/route.tsto test the Prisma client connection - Run
npm run devin theapps/my-next-appfolder to validate that the Prisma client works in the Next.js app - validates successfully
- Run
npm run previewin theapps/my-next-appfolder. - Open preview URL at
http://127.0.0.1:8787/- confirm working. - Visit
http://127.0.0.1:8787/api/test- receive error:Error: [unenv] fs.readdir is not implemented yet!