A TypeScript Express API server with PostgreSQL database for the VbloC blogging platform.
- Language: TypeScript
- Server: Express.js
- Database: PostgreSQL
- ORM: Prisma
- Validation: Zod
- Logging: Pino
- Node.js (v18 or higher)
- PostgreSQL database
- npm or yarn
-
Install dependencies:
npm install
-
Environment setup:
cp .env.example .env
Update the
.envfile with your database credentials and other configuration. -
Database setup:
# Run migrations npx prisma migrate dev # Generate Prisma client npx prisma generate
-
Start development server:
npm run dev
npm run dev- Start development server with hot reloadnpm run build- Build for productionnpm start- Start production servernpm run db:migrate- Run database migrationsnpm run db:generate- Generate Prisma clientnpm run db:studio- Open Prisma Studio
GET /api/health- Health check with database connectivityGET /api/version- Application version informationGET /api- API information
/api/auth/*- Authentication endpoints/api/users/*- User management/api/posts/*- Blog post management
backend/
├── prisma/
│ ├── migrations/ # Database migrations
│ └── schema.prisma # Database schema
├── src/
│ ├── controllers/ # Route handlers
│ ├── services/ # Business logic
│ ├── repos/ # Data access layer
│ ├── middlewares/ # Express middlewares
│ ├── utils/ # Utility functions
│ ├── db/ # Database configuration
│ ├── types/ # TypeScript type definitions
│ ├── server.ts # Express server setup
│ └── routes.ts # Route definitions
├── .env # Environment variables (not in git)
├── .env.example # Environment template
├── package.json
├── tsconfig.json
└── .gitignore
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | - |
PORT |
Server port | 4000 |
NODE_ENV |
Environment mode | development |
JWT_SECRET |
JWT signing secret (Phase 2) | - |
JWT_EXPIRES_IN |
JWT expiration time (Phase 2) | 7d |
CORS_ORIGIN |
Allowed CORS origin | http://localhost:3000 |
id- Unique identifier (CUID)email- User email (unique)username- Username (unique)passwordHash- Hashed passwordrole- User role (DEVELOPER | RECRUITER)createdAt- Creation timestampupdatedAt- Last update timestamp
- Create controller in
src/controllers/ - Add route in
src/routes.ts - Add validation schemas using Zod
- Update types in
src/types/
- Update
prisma/schema.prisma - Run
npx prisma migrate dev --name <migration_name> - Update TypeScript types if needed
The application uses Pino for structured logging:
- Request/response logging with unique request IDs
- Database connection status
- Error tracking with stack traces (development only)
- Global error handler catches all unhandled errors
- Standardized error response format
- Development vs production error details
- Request-specific error logging
- JWT authentication implementation
- User registration and login
- Blog post CRUD operations
- Comment system
- File upload handling
- Advanced pagination
- Search functionality