如何在某个路径上运行一个函数,该函数写在nodejs中的同一个文件中

时间:2021-04-25 23:54:13

What I want is to run a function on some route that function is written inside the same file.

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

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

1 个解决方案

#1


0  

You are allowed to do this but the parameters of your function must be req and res:

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

function someFunction(req, res) {
  res.send('goldfish are nice');
}

module.exports.controller = function(app) {
    app.get('/folders/create', someFunction);
}

the function you define has to actually deal with the request, otherwise the browser will just load forever and you'll eventually time out.

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

#1


0  

You are allowed to do this but the parameters of your function must be req and res:

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

function someFunction(req, res) {
  res.send('goldfish are nice');
}

module.exports.controller = function(app) {
    app.get('/folders/create', someFunction);
}

the function you define has to actually deal with the request, otherwise the browser will just load forever and you'll eventually time out.

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