This quick guide demonstrates the use of Drizzle with server components in Next.js. We breeze past the initial steps for spinning up a local PostgreSQL server and starting a Next.js app.
👉 How to use Drizzle with server components in Next.js. - Complete Documentation
First, install PostgreSQL locally and start a running database instance named drizzle_nextjs
using either psql
or pgAdmin. If you need a refresher, please refer to this YouTube tutorial.
Have the credentials of your Postgres instance ready, in a .env
file stored at the root. It should follow this format:
DB_HOST=localhost
DB_PORT_NO=5432
DB_USERNAME=postgres
DB_PASSWORD="YOUR_PASSWORD"
DB_NAME=drizzle_nextjs
DB_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT/${DB_NAME}
- Clone this repo from here.
cd
in and Install dependencies:
npm i
- Generate Drizzle migration files:
npm run db:generate
- Run database migrations:
npm run db:migrate
- Seed database:
npm run db:seed
- Run the Next.js server:
npm run dev
Visit http://localhost:3000/
. The app should be running.
Nextjs With Drizzle ORM - Free sample provided by App Generator