1.0.1 • Published 5 months ago
create-express-di-ts v1.0.1
Express TypeScript Dependency Injection Boilerplate
A lightweight, scalable Express.js boilerplate with TypeScript and Dependency Injection that follows clean architecture principles.
Features
- TypeScript support
- Dependency Injection
- Minimal setup
- Confgiuration Management
- Development ready
Project Structure
│ ├── config.ts # Application configuration management
│ ├── controllers/ # HTTP request handlers
│ │ └── UserController.ts # Example controller
│ ├── interfaces/ # TypeScript interfaces
│ │ ├── IDBRepository.ts # Repository interface
│ │ └── IUserServices.ts # Service interface
│ ├── main.ts # Application entry point
│ ├── repository/ # Data access layer
│ │ └── DBRepository.ts # Database operations implementation
│ ├── routes/ # Express routes as factory functions
│ │ └── UserRoutes.ts # User-related routes
│ ├── server.ts # Express server setup with DI container
│ └── services/ # Business logic layer
│ └── UserServices.ts # User-related business logic
├── .env # Environment variables (not in repo)
├── .env.example # Environment variables template
├── package.json # Project dependencies
└── tsconfig.json # TypeScript configuration
Getting Started
Prerequisites
- Node.js (v14+)
- TypeScript (v5+)
- Express (v4+)
Installation
- Clone the repository
# Using npx (recommended)
npx create-express-di-ts my-app
# Using npm
npm init create-express-di-ts my-app
# Using yarn
yarn cr
- Install dependencies
npm install
- Create a
.env
file based on the.env.example
cp .env.example .env
- Start the development server
npm run dev
Available Scripts
npm run dev
: Start the development servernpm run build
: Build the projectnpm run start
: Start the production servernpm run clean
: Clean the dist directory
Adding new Features
Creating a new Route
- Define your service interface in
interfaces/
- Implement your servince in
services/
- Create a controller in
controllers/
- Create a route factory in
routes/
- Add the route to the server in
server.ts