create-tsc-server

2.0.4 • Public • Published

Create TypeScript Boilerplate Server

npm version npm downloads license

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:

  1. Create a new directory named <module-name> inside the src/modules directory.

  2. 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:

  1. Clone the boilerplate repository.
  2. Create a new directory named awesome-server.
  3. Remove the .git directory from the cloned repository.
  4. 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:

  1. Start in Production: yarn start:prod
    • Runs the server using the compiled JavaScript files.
  2. Start in Development: yarn start:dev
    • Runs the server using ts-node-dev with automatic restarts and TypeScript transpilation.
  3. Build: yarn build
    • Compiles TypeScript code to JavaScript.
  4. Lint: yarn lint
    • Runs ESLint on the src directory.
  5. Lint Fix: yarn lint:fix
    • Automatically fixes ESLint issues in the src directory.
  6. Prettier: yarn prettier
    • Formats the code using Prettier.
  7. 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.

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Commit your changes (git commit -am 'Add new feature').
  5. Push to the branch (git push origin feature-branch).
  6. 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

tsc-server-npm

Package Sidebar

Install

npm i create-tsc-server

Weekly Downloads

1

Version

2.0.4

License

MIT

Unpacked Size

11.4 kB

Total Files

6

Last publish

Collaborators

  • getmonir