A production-ready RESTful search API built with Node.js, Express, Drizzle ORM, PostgreSQL, and Typesense.
This application maintains PostgreSQL as the primary source of truth while keeping Typesense synchronously and asynchronously updated to handle fast, typo-tolerant full-text searches.
- Drizzle ORM Integration: High performance, strongly-typed PostgreSQL queries.
- Batched Incremental Sync: Handles millions of rows without memory bloat using cursor-based pagination.
- Soft Delete Support: Properly handles
deleted_atfields and purges ghosts from Typesense. - Cron Jobs: Background worker keeps the database and Typesense index synchronized automatically.
- Node.js v18+
- Docker
- Start Typesense and PostgreSQL:
docker run -d -p 8108:8108 \
-v "$(pwd)"/typesense-data:/data \
typesense/typesense:27.1 \
--data-dir /data \
--api-key=xyz \
--enable-cors
docker run -d \
--name local_postgres \
-e POSTGRES_USER=admin \
-e POSTGRES_PASSWORD=admin123 \
-e POSTGRES_DB=testdb \
-p 5432:5432 \
postgres:16- Install dependencies:
npm install- Generate and Run Migrations:
Generate Drizzle migrations from
src/db/schema.tsand push them to the database.
npx drizzle-kit generate
npx drizzle-kit push- Start the application:
npm run devThe app will connect to PostgreSQL, initialize Typesense schemas, perform a startup sync (if needed), start the cron worker, and bind to http://localhost:3002.