一个基于 Node.js 全栈开发的食谱分享平台,前后端分离架构,支持食谱的发布、浏览、搜索、收藏和评论等功能。
- Node.js + Express — Web 服务框架
- MongoDB + Mongoose — 数据库
- JWT — 用户认证
- bcryptjs — 密码加密
- Multer — 文件上传
- Axios — HTTP 请求
- CORS — 跨域支持
- 前端源码通过 Vite 构建,产物部署在
client/dist/目录 - 通过 Nginx 反向代理与后端 API 通信
recipe-website/
├── client/
│ └── dist/ # 前端构建产物(Vite 构建)
│ ├── index.html
│ └── assets/
├── server/
│ ├── app.js # 应用入口
│ ├── init-db.js # 数据库初始化脚本
│ ├── addRecipes.js # 添加示例食谱
│ ├── addRecipesDirect.js
│ ├── controllers/ # 控制器
│ │ ├── authController.js
│ │ ├── recipeController.js
│ │ ├── favoriteController.js
│ │ └── commentController.js
│ ├── models/ # 数据模型
│ │ ├── User.js
│ │ ├── Recipe.js
│ │ ├── Favorite.js
│ │ └── Comment.js
│ ├── routes/ # 路由
│ │ ├── auth.js
│ │ ├── recipes.js
│ │ ├── upload.js
│ │ ├── favorites.js
│ │ └── comments.js
│ ├── middleware/ # 中间件
│ │ └── auth.js
│ ├── uploads/ # 上传文件目录
│ ├── package.json
│ └── .env # 环境变量(不入库)
├── deploy-server.sh # 服务器部署脚本
└── .gitignore
- 🔐 用户系统 — 注册、登录、JWT 认证
- 📝 食谱管理 — 发布、编辑、删除食谱
- 🖼️ 图片上传 — 支持封面图和步骤图片上传
- 🔍 搜索功能 — 支持按标题和描述全文搜索
- 🏷️ 菜系分类 — 川菜、粤菜、湘菜、鲁菜、苏菜、浙菜、闽菜、徽菜等八大菜系
- ⭐ 收藏功能 — 收藏喜欢的食谱
- 💬 评论系统 — 对食谱进行评论互动
- 👁️ 浏览量统计 — 记录食谱浏览次数
- 📊 食谱属性 — 烹饪时间、难度、餐类(早餐/午餐/晚餐/小吃)
git clone https://gitee.com/tong-bei/recipe-website.git
cd recipe-websitecd server
npm installcp .env.example .env
# 编辑 .env 文件,配置数据库连接等信息.env 文件配置项:
PORT=3000
MONGODB_URI=mongodb://localhost:27017/recipe-db
JWT_SECRET=your_jwt_secret_key
node init-db.js# 开发模式(支持热重载)
npm run dev
# 生产模式
npm start服务默认运行在 http://localhost:3000。
参考 deploy-server.sh 中的 Nginx 配置示例。
| 方法 | 路径 | 说明 |
|---|---|---|
| POST | /api/auth/register | 用户注册 |
| POST | /api/auth/login | 用户登录 |
| GET | /api/recipes | 获取食谱列表 |
| GET | /api/recipes/:id | 获取食谱详情 |
| POST | /api/recipes | 创建食谱 |
| PUT | /api/recipes/:id | 更新食谱 |
| DELETE | /api/recipes/:id | 删除食谱 |
| GET | /api/cuisines | 获取菜系列表 |
| POST | /api/upload | 上传图片 |
| POST | /api/favorites | 添加收藏 |
| DELETE | /api/favorites/:recipeId | 取消收藏 |
| GET | /api/favorites | 获取收藏列表 |
| POST | /api/comments | 添加评论 |
| GET | /api/comments/:recipeId | 获取食谱评论 |
MIT