A production-ready Node.js + TypeScript API template featuring Express, Knex, Zod validation, and a clean layered architecture.
Designed for building scalable backend services with clear separation of concerns and a strong developer experience.
- Node.js + TypeScript - modern, strongly typed backend foundation
- Express - minimal and flexible API routing
- Knex.js - SQL query builder (supports MySQL, PostgreSQL, SQLite, and more)
- Zod - schema validation + DTO enforcement
- Clean Architecture
- Routes
- Controllers
- Services
- Repositories
- DTOs
- Environment variable support using dotenv
- CORS enabled
- Development server with ts-node-dev
- Production build with TypeScript compiler
src/
├─ app.ts
├─ server.ts
├─ db/
│ └─ knex.ts
├─ routes/
│ └─ example.routes.ts
├─ controllers/
│ └─ example.controller.ts
├─ services/
│ └─ example.service.ts
├─ repositories/
│ └─ example.repository.ts
├─ dtos/
│ └─ example.dto.ts
.env.example
tsconfig.json
package.json
.gitignore
Routes – define API endpoints
Controllers – handle HTTP requests/responses
Services – business logic
Repositories – database operations
DTOs – input validation using Zod
Clone this repository:
git clone https://github.com/edwardgnt/node-ts-api-template.git
cd node-ts-api-template
Install dependencies:
npm install
Copy environment file:
cp .env.example .env
Server runs at:
http://localhost:5001
Production Build:
npm run build
npm start
Example Endpoint:
GET /api/example
Response: { "message": "Hello from the repository layer!" }