hono-cli

1.0.6 • Public • Published

Hono-CLI 🦊

A powerful CLI tool for scaffolding and managing Hono.js projects. Create new projects, generate modules, and streamline your development workflow with MongoDB integration.

Features ✨

  • Quick project initialization with best practices
  • Module generation with CRUD operations
  • MongoDB integration out of the box
  • Swagger documentation
  • Type-safe routes with Hono
  • Path aliases for better imports
  • Environment configuration
  • Developer-friendly CLI interface

Installation 🚀

npm install -g hono-cli
# or
bun install -g hono-cli

Usage 📚

Create New Project

hono-cli init my-project

This will create a new Hono.js project with the following structure:

my-project/
├── src/
│   ├── modules/      # Feature modules
│   ├── shared/       # Shared utilities and middleware
│   │   ├── middleware/
│   │   └── utils/
│   ├── config/      # Configuration files
│   ├── index.ts     # Application entry point
│   └── routes.ts    # Route manager
├── .env             # Environment variables
├── .gitignore
├── package.json
├── README.md
└── tsconfig.json

Generate Module

hono-cli g:m user

This generates a new module with:

  • Controller with CRUD operations
  • Service layer with MongoDB integration
  • Type definitions
  • Route configuration with Swagger docs
  • Automatic route registration

Generated module structure:

src/modules/user/
├── user.controller.ts
├── user.service.ts
├── user.routes.ts
├── user.types.ts
├── user.validation.ts
└── index.ts

Generate Router Only

hono-cli g:r user

This generates a minimal module with just routing functionality:

src/modules/user/
├── user.routes.ts
└── index.ts

The router generator:

  • Creates only routing-related files
  • Automatically registers routes in the route manager
  • Perfect for simple API endpoints without complex business logic

Version Check

hono-cli version
# or
hono-cli v

Shows detailed package information:

  • Current package version
  • List of installed dependencies and their versions
  • List of development dependencies and their versions

Configuration 🛠

Database

Database configuration is located in src/config/db.config.ts:

export const dbConfig = {
  development: {
        url: process.env.DB_URL || 'mongodb://localhost:27017',
        name: process.env.DB_NAME || 'hono_dev'
    },
  test: {
        url: process.env.TEST_DB_URL || 'mongodb://localhost:27017',
        name: process.env.TEST_DB_NAME || 'hono_test',
        options: {
            maxPoolSize: 5,
            minPoolSize: 1
        }
    },
    production: {
        url: process.env.PROD_DB_URL || 'mongodb://localhost:27017',
        name: process.env.PROD_DB_NAME || 'hono_prod',
        options: {
            maxPoolSize: 20,
            minPoolSize: 10,
            retryWrites: true,
            retryReads: true
        }
    }
}

Environment Variables

Available environment variables:

NODE_ENV=development
PORT=3000

# Database Configuration
DB_URL=mongodb://localhost:27017
DB_NAME=hono_dev

# Production Database
PROD_DB_URL=mongodb://your-production-url:27017
PROD_DB_NAME=hono_prod

Commands Reference 📖

Command Description
hono-cli init <name> Create new Hono.js project
hono-cli g:m <name> Generate new module with CRUD

Project Structure 🏗

src/
├── modules/           # Feature modules
│   └── user/         # Example module
│       ├── user.controller.ts
│       ├── user.service.ts
│       ├── user.routes.ts
│       └── user.types.ts
├── shared/
│   ├── middleware/   # Custom middleware
│   └── utils/        # Utility functions
├── config/           # Configuration files
│   ├── db.config.ts
│   └── collections.config.ts
├── index.ts          # Application entry
└── routes.ts         # Route manager

Best Practices 💡

  1. Module Organization:

    • Keep related functionality together
    • Use clear naming conventions
    • Separate concerns (controller, service, routes)
  2. Database Handling:

    • Use services for database operations
    • Implement proper error handling
    • Follow MongoDB best practices
  3. Type Safety:

    • Define clear interfaces
    • Use TypeScript features
    • Validate API inputs

Contributing 🤝

Contributions are welcome! Please feel free to submit a Pull Request.

License 📄

MIT © Alex Veros

Author ✨

Alex Veros

Package Sidebar

Install

npm i hono-cli

Weekly Downloads

4

Version

1.0.6

License

MIT

Unpacked Size

126 kB

Total Files

3

Last publish

Collaborators

  • jorlex