simple-express-typescript-generator
v1.0.4
Published
CLI generator for Express TypeScript projects
Maintainers
Readme
Simple Express Generator
A CLI tool to quickly scaffold Express TypeScript projects with a well-organized structure.
Features
- 🚀 Quick Setup: Generate a complete Express TypeScript project in seconds
- 📁 Organized Structure: Pre-configured project structure with best practices
- 🛠️ TypeScript Ready: Full TypeScript support with proper configurations
- 🧪 Testing Setup: Jest and Supertest integration tests included
- 📝 Error Handling: Centralized error handling with custom AppError class
- 🪵 Logging: Built-in Logger utility for structured logging
- 🏗️ Modular Architecture: Controllers, Services, Routers, and Middlewares
Installation
Global Installation (Recommended)
npm install -g simple-express-generatorLocal Development
git clone <repository-url>
cd simple-express-generator
npm install
npm run build
npm linkUsage
Create a New Project
simple-express-generator create my-express-appOptions
--directory <dir>: Specify the directory to create the project in (default: current directory)
Example
# Create a new project called "my-api"
simple-express-generator create my-api
# Create a project in a specific directory
simple-express-generator create my-api --directory ./projectsGenerated Project Structure
my-express-app/
├── index.ts # Application entry point
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── jest.config.js # Jest test configuration
├── src/
│ ├── app.ts # Express app configuration
│ ├── controllers/
│ │ └── HelloController.ts
│ ├── middlewares/
│ │ ├── errorHandler.ts
│ │ └── unknownRouteHandler.ts
│ ├── routers/
│ │ └── helloRouter.ts
│ ├── services/
│ │ └── helloService.ts
│ └── utils/
│ ├── AppError.ts
│ └── Logger.ts
└── test/
└── hello.integration.test.tsGetting Started with Generated Project
After creating your project:
Navigate to your project directory:
cd my-express-appInstall dependencies:
npm installStart development server:
npm run devBuild for production:
npm run buildRun tests:
npm test
Available Scripts in Generated Project
npm run dev- Start development server with hot reloadnpm run build- Build the project for productionnpm start- Start the production servernpm test- Run tests
API Endpoints
The generated project includes a sample API endpoint:
GET /api/hello/- Returns a simple "dummy" response
Architecture
The generated project follows a clean architecture pattern:
- Controllers: Handle HTTP request/response logic
- Services: Contain business logic
- Routers: Define routes and middleware
- Middlewares: Manage errors and unknown routes
- Utils: Shared utilities and helper functions
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the ISC License - see the LICENSE file for details.
Support
If you encounter any issues or have questions, please open an issue on the GitHub repository.
