Skip to content

edwinhern/express-typescript-2024

Repository files navigation

🚀 Express TypeScript Boilerplate 2024

Build Express Application CodeQL Docker Image CI Release

🌟 Introduction

Welcome to the Express TypeScript Boilerplate 2024 – a streamlined, efficient, and scalable foundation for building powerful backend services. This boilerplate merges modern tools and practices in Express.js and TypeScript, enhancing productivity, code quality, and performance.

💡 Motivation and Intentions

Developed to streamline backend development, this boilerplate is your solution for:

  • ✨ Reducing setup time for new projects.
  • 📊 Ensuring code consistency and quality.
  • ⚡ Facilitating rapid development with cutting-edge tools.
  • 🛡️ Encouraging best practices in security, testing, and performance.

🚀 Features

  • 📁 Modular Structure: Organized by feature for easy navigation and scalability.
  • 💨 Faster Execution with tsx: Rapid TypeScript execution with esbuild, complemented by tsc for type checking.
  • 🌐 Stable Node Environment: Latest LTS Node version in .nvmrc.
  • 🔧 Simplified Environment Variables with Envalid: Centralized and easy-to-manage configuration.
  • 🔗 Path Aliases: Cleaner code with shortcut imports.
  • 🔄 Dependabot Integration: Automatic updates for secure and up-to-date dependencies.
  • 🔒 Security: Helmet for HTTP header security and CORS setup.
  • 📊 Logging: Efficient logging with pino-http.
  • 🧪 Comprehensive Testing: Robust setup with Vitest and Supertest.
  • 🔑 Code Quality Assurance: Husky and lint-staged for consistent quality.
  • ✅ Unified Code Style: ESLint and Prettier for a consistent coding standard.
  • 📃 API Response Standardization: ServiceResponse class for consistent API responses.
  • 🐳 Docker Support: Ready for containerization and deployment.
  • 📝 Input Validation with Zod: Strongly typed request validation using Zod.
  • 🧩 API Spec Generation: Automated OpenAPI specification generation from Zod schemas to ensure up-to-date and accurate API documentation.

🛠️ Getting Started

Step 1: 🚀 Initial Setup

  • Clone the repository: git clone https://github.com/edwinhern/express-typescript-2024.git
  • Navigate: cd express-typescript-2024
  • Install dependencies: npm ci

Step 2: ⚙️ Environment Configuration

  • Create .env: Copy .env.template to .env
  • Update .env: Fill in necessary environment variables

Step 3: 🏃‍♂️ Running the Project

  • Development Mode: npm run dev
  • Building: npm run build
  • Production Mode: Set .env to NODE_ENV="production" then npm run build && npm run start

📁 Project Structure

.
├── api
│   ├── healthCheck
│   │   ├── __tests__
│   │   │   └── healthCheckRouter.test.ts
│   │   └── healthCheckRouter.ts
│   └── user
│       ├── __tests__
│       │   ├── userRouter.test.ts
│       │   └── userService.test.ts
│       ├── userModel.ts
│       ├── userRepository.ts
│       ├── userRouter.ts
│       └── userService.ts
├── api-docs
│   ├── __tests__
│   │   └── openAPIRouter.test.ts
│   ├── openAPIDocumentGenerator.ts
│   ├── openAPIResponseBuilders.ts
│   └── openAPIRouter.ts
├── common
│   ├── __tests__
│   │   ├── errorHandler.test.ts
│   │   └── requestLogger.test.ts
│   ├── middleware
│   │   ├── errorHandler.ts
│   │   ├── rateLimiter.ts
│   │   └── requestLogger.ts
│   ├── models
│   │   └── serviceResponse.ts
│   └── utils
│       ├── commonValidation.ts
│       ├── envConfig.ts
│       └── httpHandlers.ts
├── index.ts
└── server.ts

🤝 Feedback and Contributions

We'd love to hear your feedback and suggestions for further improvements. Feel free to contribute and join us in making backend development cleaner and faster!

🎉 Happy coding!