Drizzle PostgreSQL Starter

The Drizzle PostgreSQL Starter is a database foundation provided by servercn for projects that use PostgreSQL with Drizzle ORM. When you run:

Installation Guide

npx servercn init drizzle-pg-starter

you get a production‑ready PostgreSQL + Drizzle setup that integrates cleanly with the Express Server Foundation.

This starter focuses on type‑safe database access, clear schema ownership, and predictable migrations, without hiding SQL or introducing heavy abstractions.

Official Docs

What This Starter Solves

Setting up Drizzle with PostgreSQL repeatedly involves:

  • Database connection management
  • Schema organization
  • Migration configuration
  • Environment‑based credentials
  • Type safety across queries

The Drizzle PostgreSQL Starter standardizes these concerns using a minimal, explicit setup.

What You Get Out of the Box

After initialization, your project includes:

  • Drizzle ORM configured for PostgreSQL
  • Type‑safe schema definitions
  • Centralized database client
  • Environment‑based database config
  • Safe startup validation
  • Production‑ready connection handling
  • Drizzle migration setup
  • Structured migration folder
  • CLI‑ready workflow
  • Fully typed queries
  • Clean schema organization
  • Zero runtime magic

Environment Configuration

Database credentials are loaded via environment variables.

NODE_ENV='development'
PORT='9000'
LOG_LEVEL='info'
 
DATABASE_URL=PostgreSQL://root:password@localhost:3306/db-name

The server fails fast if required database variables are missing.

Defining Schemas

Schemas are written using Drizzle’s SQL‑first, type‑safe API.

src/drizzle/schema.ts
import { PgTable, serial, varchar } from "drizzle-orm/pg-core";
 
export const usersTable = PgTable("users_table", {
  id: serial().primaryKey(),
  name: varchar({ length: 255 }).notNull(),
  email: varchar({ length: 255 }).notNull().unique(),
  password: varchar("password", { length: 255 }).notNull()
});

Schemas are:

  • Explicit
  • Version‑controlled
  • Fully typed across queries

Database Client Setup

src/configs/db.ts or src/db/db.ts

import { drizzle } from "drizzle-orm/node-postgres";
import env from "./env";
 
const db = drizzle(env.DATABASE_URL!);
 
export default db;

No repositories or hidden layers — you interact directly with Drizzle.

Migrations Workflow

npm run db:generate
npm run db:migrate

Migrations are SQL‑first and fully auditable.

npm run db:studio

Summary

The Drizzle PostgreSQL Starter gives you a clean, production‑ready database foundation using PostgreSQL + Drizzle ORM.

It prioritizes clarity, type safety, and long‑term maintainability — without taking control away from you.

Installation

npx servercn init drizzle-pg-starter