javascript - 将路由器逻辑拆分为单独的功能
问题描述
我在 Node.js 中有一个路由器的获取请求处理程序,它有很多代码:
const express = require("express");
const router = express.Router();
router.get("/api/employees/employee-response", async (req, res) => {
try {
// First action with code
// Second action with code
// Third action with code
}
catch(exp) {
// ...
}
module.exports = router;
如何将其拆分为小函数并从路由器调用这些函数?
解决方案
推荐阅读
- angular - Angular 自定义表单控件永远不会让我的表单变脏
- javascript - 如何获取包含阿根廷等国籍的演员按全名排序:输入网址邮递员时出错
- flutter - 是否能够使用带有提供程序的无状态小部件为动画容器设置动画
- java - 我们可以从抽象类创建对象吗?
- python - 如何在seaborn中绘制选择Y值
- node.js - 如何在 tor 上发布我的 node.js 服务器?
- ibm-cloud - IBM Watson Assistant:如何存储任何类型的输入?
- github-actions - 带有自托管 Windows-Runner 的 GitHub Actions“找不到文件:'bash'”
- flutter - 在底部导航栏中颤动自定义形状按钮
- makefile - Makefile 结合类似的规则