UNPKG

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
# πŸš€ 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]_