npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

radish-express-cli

v1.0.1

Published

Radish Express 项目脚手架工具 - 快速创建基于 Express 的 Node.js 项目

Downloads

7

Readme

Radish Express CLI

Radish Express 项目脚手架工具

快速创建基于 Express 的 Node.js 项目,内置完善的项目结构和常用工具。

特性

  • 🚀 快速创建项目,开箱即用
  • 📦 自动安装依赖
  • 🔄 可选更新依赖到最新版本
  • 🗄️ 可选集成 MongoDB 数据库
  • 🛡️ 内置安全中间件 (helmet, cors)
  • 📝 集成日志系统 (morgan)
  • ⚡ 支持热重载开发 (nodemon)
  • 🔐 JWT 令牌支持
  • 🔒 密码加密 (bcrypt)
  • 🌍 环境变量管理 (dotenv-flow)
  • 🚦 API 限流保护

安装

全局安装

npm install -g radish-express-cli

使用 npx (无需安装)

npx radish-express-cli my-project

使用方法

创建新项目

radish-express my-project

或者直接运行命令,交互式输入项目名称:

radish-express

交互式选项

运行命令后,会提示以下选项:

  1. 项目名称: 输入项目名称 (仅支持小写字母、数字、连字符和下划线)
  2. 是否包含 MongoDB 功能: 选择是否集成 MongoDB 数据库
  3. 是否更新依赖到最新版本: 选择是否将依赖更新到最新版本

启动项目

cd my-project
npm run dev

项目结构

my-project/
├── src/
│   ├── config/          # 配置文件
│   ├── controllers/     # 控制器
│   ├── middlewares/     # 中间件
│   │   ├── ErrorHandler.js
│   │   ├── NotFoundHandler.js
│   │   ├── RateLimiter.js
│   │   └── ResponseFormatter.js
│   ├── models/          # 数据模型
│   ├── routes/          # 路由
│   ├── services/        # 业务逻辑
│   ├── utils/           # 工具类
│   │   ├── Crypto.js
│   │   ├── Database.js  (可选)
│   │   ├── HttpClient.js
│   │   ├── Logger.js
│   │   └── Token.js
│   └── app.js           # Express 应用配置
├── modules/             # 扩展模块
├── scripts/             # 脚本文件
├── logs/                # 日志目录
├── index.js             # 入口文件
├── package.json
├── .env.development     # 开发环境配置
├── .env.production      # 生产环境配置
├── .gitignore
├── .prettierrc          # Prettier 配置
└── nodemon.json         # Nodemon 配置

内置依赖

核心依赖

  • express - Web 框架
  • dotenv-flow - 环境变量管理
  • mongoose - MongoDB ODM (可选)

安全相关

  • helmet - 安全响应头
  • cors - 跨域资源共享
  • express-rate-limit - API 限流
  • bcrypt - 密码加密
  • jsonwebtoken - JWT 令牌

工具类

  • axios - HTTP 客户端
  • crypto-js - 加密工具
  • morgan - HTTP 请求日志
  • moment - 日期时间处理
  • uuid - UUID 生成
  • chalk - 终端颜色输出
  • clipboardy - 剪贴板操作

开发工具

  • nodemon - 热重载
  • cross-env - 跨平台环境变量
  • prettier - 代码格式化

环境配置

项目使用 dotenv-flow 管理环境变量,支持以下配置文件:

  • .env.development - 开发环境
  • .env.production - 生产环境

基础配置

# 工作模式
NODE_ENV=development

# 服务配置
SERVER_HOST=0.0.0.0
SERVER_PORT=3000

# MongoDB 配置 (如果选择了 MongoDB)
MONGO_URI=mongodb://localhost:27017/your-database

# 算法密钥配置
AES_KEY=your-aes-key
AES_IV=your-aes-iv

# 令牌生成配置
JWT_SECRET=your-jwt-secret

# 反向代理配置
TRUST_PROXY=0

可用脚本

# 开发模式运行
npm run dev

# 生产模式运行
npm run prod

MongoDB 功能

如果选择包含 MongoDB 功能,项目将包含:

  • src/utils/Database.js - 数据库连接工具类
  • mongoose 依赖
  • 数据库相关环境变量配置
  • 自动连接和断开数据库

如果不包含 MongoDB,这些内容将被自动移除。

依赖更新

创建项目时可以选择是否更新依赖到最新版本:

  • 选择"是": 使用 npm-check-updates 更新所有依赖到最新版本
  • 选择"否": 使用模板中预设的稳定版本

注意: chalk 库会被排除在自动更新之外,以保持兼容性。

最佳实践

目录规范

  • controllers/ - 处理 HTTP 请求和响应
  • services/ - 业务逻辑层
  • models/ - 数据模型定义
  • routes/ - 路由定义
  • middlewares/ - 自定义中间件
  • utils/ - 通用工具函数
  • config/ - 应用配置文件

代码风格

项目内置 Prettier 配置,建议安装 VSCode 的 Prettier 插件并启用保存时格式化。

日志管理

  • 开发环境: 使用 dev 格式输出到控制台
  • 生产环境: 使用 combined 格式,可配置输出到文件

错误处理

项目内置统一的错误处理中间件,所有错误都会被捕获并格式化返回。

常见问题

1. 项目创建后依赖安装失败?

cd my-project
npm install

2. 如何修改服务器端口?

编辑 .env.development.env.production 文件中的 SERVER_PORT 配置。

3. 如何连接 MongoDB?

编辑环境配置文件中的 MONGO_URI,格式:

MONGO_URI=mongodb://[username:password@]host[:port]/database

4. 如何添加新的路由?

  1. src/routes/ 创建路由文件
  2. src/app.js 中注册路由

5. 如何自定义中间件?

src/middlewares/ 目录下创建中间件文件,然后在 src/app.js 中引入并使用。

开发计划

  • [ ] 支持 TypeScript 模板
  • [ ] 支持更多数据库选项 (MySQL, PostgreSQL)
  • [ ] 集成 Swagger API 文档
  • [ ] 支持 Docker 配置
  • [ ] 集成单元测试框架

贡献指南

欢迎提交 Issue 和 Pull Request!

本地开发

# 克隆仓库
git clone https://github.com/Sunquymans/radish-express-cli.git
cd radish-express-cli

# 安装依赖
npm install

# 本地测试
npm link
radish-express test-project

技术支持

如有问题或建议,请提交 Issue

更新日志

1.0.0 (2025-01-14)

  • 🎉 首次发布
  • ✨ 支持交互式创建项目
  • ✨ 可选 MongoDB 功能
  • ✨ 可选依赖更新
  • ✨ 自动安装依赖

开源协议

MIT © Sunquyman