首页 > 解决方案 > 将路由器逻辑拆分为单独的功能

问题描述

我在 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;

如何将其拆分为小函数并从路由器调用这些函数?

标签: javascriptnode.jsexpressexpress-router

解决方案


推荐阅读