create-types-backend
Version:
A CLI tool to quickly setup an Express.js backend in TypeScript, using essential configurations and user's preferences.
125 lines (94 loc) β’ 4.56 kB
Markdown
# π TypeScript-Express Backend Setup CLI
A CLI tool to quickly setup an **Express.js backend** in **TypeScript**, using essential configurations and user's preferences.
## β‘ Installation
You can directly run the CLI (using **npx**) or install globally (using **npm install -g**) :
```sh
# Run directly using npx
npx create-types-backend
# OR Install globally (optional)
npm install -g create-types-backend
```
## π¦ Features
β
**Generates a well-structured Express-TypeScript backend**
β
**Supports automatic setup using `-y` flag**
β
**Includes Express.js, Typescript, DotEnv and essential configurations**
β
**Sets up tsx for hot-reloading while development**
β
**Resolves default import alias by mapping src -> @**
## βοΈ Optional support for:
- Custom Error Handlers
- CORS
- MongoDB
- JWT, bcrypt, cookie-parser
- Multer
- Cloudinary
- ES-Lint
- Docker
## π Usage
β‘οΈ Creating a new project
```sh
npx create-types-backend : Manual setup with flexibility to choose required configurations.
OR
npx create-types-backend -y : Run in default mode with all preferences set to 'YES'
OR
npx create-types-backend myapp : Enter project name through CLI argument
```
β‘οΈ Starting the Development Server
```sh
Just follow these 3 steps:
- cd into the newly created backend directory
- add your MONGODB_URI in .env file (if using MongoDB)
- npm run dev OR npm run docker:dev (if using docker)
```
## π οΈ Project Structure
```sh
myapp/
βββ src/
βββ config/ # Configuration files (e.g., database)
βββdb.ts # MongoDB connection setup
βββmulter.ts # Multer setup
βββ constants/ # Constant values
βββcookie-options.ts # Cookie options for JWT
βββ controllers/ # Route handlers
βββuser.ts # Example controller
βββ helpers/ # Helper functions
βββ middlewares/ # Express middlewares
βββerrorHandler.ts # Custom error handler
βββ models/ # Mongoose models
βββuser.ts # Example mongoose model
βββ routes/ # API routes
βββuser.ts # Example route
βββ types/ # TypeScript types
βββfile.d.ts # FileTypes definition (reqd for cloudinary)
βββuser.d.ts # UserTypes definition (acc to example mongoose schema)
βββ utils/ # Reusable utilities
βββcloudinary.ts # Cloudinary upload and delete controllers
βββgenerate-token.ts # Generate JWT token and set cookie
βββtry-catch.ts # Try-Catch wrapper for async functions
βββ app.ts # Main entry point of express app
βββ .dockerignore # Docker ignore file
βββ .env # Environment variables
βββ .env.example # Example environment variables
βββ .gitignore # Git ignore file
βββ .prettierrc # Prettier configuration
βββ docker-compose.yaml # Docker-Compose file configured for development
βββ Dockerfile # Dockerfile for production
βββ Dockerfile.dev # Dockerfile for development
βββ eslint.config.js # ESLint configuration for code linting
βββ package.json # Project metadata & dependencies
βββ tsconfig.json # TypeScript configuration
```
## π€ Contributing
Want to improve this CLI? Feel free to **fork** the project, make changes, and submit a **pull request (PR)**.
### Steps to Contribute:
1. Fork this repository.
2. Clone your fork locally.
3. Create a new branch for your feature/fix.
4. Commit your changes and push them.
5. Submit a pull request for review.
## π License
This project is **open-source** and available under the **ISC License**.
## π¨βπ» Author
**Raghav Bhagat**
π GitHub: _[https://github.com/rbhagat32]_
π NPM: _[https://www.npmjs.com/~raghavbhagat32]_
π LinkedIn: _[https://www.linkedin.com/in/rbhagat32]_