An Express + Drizzle ORM backend for managing books and authors on PostgreSQL. The app exposes simple JSON endpoints for creating, listing, searching, and deleting books, plus author management and author-to-books lookups.
- Node.js
- Express 5
- Drizzle ORM and Drizzle Kit
- PostgreSQL
index.jsstarts the server and mounts the routers.controllers/contains request handlers for book operations.routes/defines the HTTP endpoints for books and authors.models/defines the Drizzle table schemas.db/creates the Drizzle database client.middlewares/logger.jsappends each request tologs.txt.docker-compose.ymlstarts a local PostgreSQL instance.
npm installdocker compose up -d postgresSet the database connection string in your environment before starting the app.
Use the same value in your local shell or editor settings.
The schema is defined in models/ and wired into drizzle.config.js. If you need to push the schema to the database, run:
npx drizzle-kit pushnpm startThe server listens on port 8000.
| Method | Route | Description |
|---|---|---|
| GET | /books |
List all books |
| GET | /books?search=term |
Full-text search books by title |
| GET | /books/:id |
Get a single book with its author |
| POST | /books |
Create a book |
| DELETE | /books/:id |
Delete a book |
Create book body:
{
"title": "Clean Code",
"authorId": "<author-uuid>",
"description": "A practical guide to writing clean software"
}| Method | Route | Description |
|---|---|---|
| GET | /authors |
List all authors |
| GET | /authors/:id |
Get one author |
| GET | /authors/:id/books |
List books for an author |
| POST | /authors |
Create an author |
Create author body:
{
"firstName": "Robert",
"lastName": "Martin",
"email": "unclebob@example.com"
}Every request is written to logs.txt with a timestamp, method, and path.
- Book search uses PostgreSQL full-text search.
- Books reference authors through a foreign key.
- The app is CommonJS-based and runs with
node --watchin development.