create-tsc-server
v2.0.4
Published
A package for creating TypeScript Node.js Express server boilerplate with modular architecture and essential features.
Downloads
46
Maintainers
Readme
Create TypeScript Boilerplate Server
create-tsc-server
is a command-line tool that helps you quickly create a boilerplate TypeScript server by cloning a predefined GitHub repository.
Features
- 🚀 Quick Setup: Instantly clone a TypeScript server template and get started.
- 💡 Easy to Use: Simple command to create a new server project.
- 📦 Production and Development Scripts: Scripts to start the server in production and development modes.
- 🛠️ Build Script: Compile TypeScript code to JavaScript.
- 🧹 Linting and Formatting: ESLint and Prettier configurations for code quality.
- 🔐 Security: Built-in support for JWT authentication and bcrypt for password hashing.
- 🌐 Middleware: Includes cookie-parser, CORS, and dotenv for environment variables.
- 📦 Database: Mongoose integration for MongoDB.
- 📂 builtin module create:Automatically create import module files.
Update
Creating a New Module
To create a new module within your existing TypeScript server project, use the following command:
npx tsc-module <module-name>
This command will:
Create a new directory named
<module-name>
inside thesrc/modules
directory.Generate the following files inside the new directory:
<module-name>.constant.ts
<module-name>.controller.ts
<module-name>.interface.ts
<module-name>.model.ts
<module-name>.route.ts
<module-name>.service.ts
<module-name>.utils.ts
<module-name>.validation.ts
Each file will contain a basic template to get you started quickly.
Example
npx tsc-module user
This will create the following structure inside src/modules
:
- User/
- user.constant.ts
- user.controller.ts
- user.interface.ts
- user.model.ts
- user.route.ts
- user.service.ts
- user.utils.ts
- user.validation.ts
Installation
You can install create-tsc-server
globally using npm:
npm install -g create-tsc-server
Or use it directly with npx (no installation required):
npx create-tsc-server <app-name>
Usage
To create a new TypeScript server project, run:
npx create-tsc-server my-app
Replace my-app with your desired project name.
This will:
- Clone the boilerplate repository.
- Create a new directory named awesome-server.
- Remove the .git directory from the cloned repository.
- Set up your new TypeScript server project.
Boilerplate Repository
The tool clones the repository from GitHub.
Project Structure
The generated project includes:
📦 src
├─ app
│ ├─ builder
│ ├─ config
│ ├─ DB
│ ├─ errors
│ │ ├─ AppError.ts
│ │ ├─ handleCastError.ts
│ │ ├─ handleDuplicateError.ts
│ │ ├─ handleValidationError.ts
│ │ └─ handleZodError.ts
│ ├─ helpers
│ ├─ interface
│ │ ├─ error.ts
│ │ └─ index.d.ts
│ ├─ middlewares
│ │ ├─ authGaurd.ts
│ │ ├─ globalErrorHandler.ts
│ │ ├─ notFoundAPIHandler.ts
│ │ └─ validateRequest.ts
│ ├─ routes
modules
│ │ └─ ExampleMoudles
│ │ ├─ user.constant.ts
│ │ ├─ user.controller.ts
│ │ ├─ user.interface.ts
│ │ ├─ user.model.ts
│ │ ├─ user.route.ts
│ │ ├─ user.service.ts
│ │ ├─ user.utils.ts
│ │ └─ user.validation.ts
│ ├─ shared
│ └─ utils
│ ├─ catchAsync.ts
│ └─ sendResponse.ts
├─ server.t
├─ app.ts
├─ tsconfig.json
├─ .env.example
├─ .prettierrc.json
├─ eslint.config.mjs
└─ yarn.lock
©generated by Project Tree Generator
Scripts
The package.json includes several useful scripts:
- Start in Production:
yarn start:prod
- Runs the server using the compiled JavaScript files.
- Start in Development:
yarn start:dev
- Runs the server using ts-node-dev with automatic restarts and TypeScript transpilation.
- Build:
yarn build
- Compiles TypeScript code to JavaScript.
- Lint:
yarn lint
- Runs ESLint on the src directory.
- Lint Fix:
yarn lint:fix
- Automatically fixes ESLint issues in the src directory.
- Prettier:
yarn prettier
- Formats the code using Prettier.
- Prettier Fix:
yarn prettier:fix
- Automatically formats the code in the src directory.
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any bugs, improvements, or features you'd like to see.
- Fork the repository.
- Create a new branch (git checkout -b feature-branch).
- Make your changes.
- Commit your changes (git commit -am 'Add new feature').
- Push to the branch (git push origin feature-branch).
- Open a Pull Request.
Dependencies
Production
- @typescript-eslint/eslint-plugin
- @typescript-eslint/parser
- bcrypt
- cookie-parser
- cors
- dotenv
- eslint
- express
- http-status
- jsonwebtoken
- mongoose
- zod
Development
- @eslint/js
- @types/bcrypt
- @types/cookie-parser
- @types/cors
- @types/express
- @types/jsonwebtoken
- @types/node
- eslint-config-prettier
- globals
- prettier
- ts-node
- ts-node-dev
- typescript
- typescript-eslint
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contact
For any questions or feedback, feel free to reach out via GitHub Issues.
Made with ❤️ by MD. Monir Hoshen, GitHub Profile