如何在nodejs中的同一文件中编写的某个路由上运行函数

How to run a function on some route which is written in the same file in nodejs

本文关键字:路由 函数 运行 文件 nodejs      更新时间:2023-09-26

我想要的是在某个路由上运行一个函数,该函数写在同一个文件中。

module.exports.controller = function(app) {
    app.get('/folders/create', createDirectory);
}
var createDirectory = function(path, name, permissions, version, type)

您可以这样做,但函数的参数必须是reqres:

function someFunction(req, res) {
  res.send('goldfish are nice');
}
module.exports.controller = function(app) {
    app.get('/folders/create', someFunction);
}

您定义的函数必须实际处理请求,否则浏览器将永远加载,您最终会超时。