新版本的快递上有一些中间件变化,我在这个问题上围绕其他一些帖子对我的代码进行了一些更改,但我无法坚持下去.
我们手头工作但我不记得改变是什么.
throw new TypeError('Router.use() requires middleware function but got a
^
TypeError: Router.use() requires middleware function but got a Object
Run Code Online (Sandbox Code Playgroud)
node ./bin/www
js-bson: Failed to load c++ bson extension, using pure JS version
js-bson: Failed to load c++ bson extension, using pure JS version
Run Code Online (Sandbox Code Playgroud)
/Users/datis/Documents/bb-dashboard/node_modules/express/lib/router/index.js:438
throw new TypeError('Router.use() requires middleware function but got a
^
TypeError: Router.use() requires middleware function but got a Object
at /Users/datis/Documents/bb-dashboard/node_modules/express/lib/router/index.js:438:13
at Array.forEach (native)
at Function.use (/Users/datis/Documents/bb-dashboard/node_modules/express/lib/router/index.js:436:13)
at /Users/datis/Documents/bb-dashboard/node_modules/express/lib/application.js:188:21
at Array.forEach (native)
at Function.use …Run Code Online (Sandbox Code Playgroud) 看着一个随机的源文件中的express为框架NodeJS,有我不理解的代码的两行(这行代码是典型的几乎所有文件的NodeJS).
/**
* Expose `Router` constructor.
*/
exports = module.exports = Router;
Run Code Online (Sandbox Code Playgroud)
和
/**
* Expose HTTP methods.
*/
var methods = exports.methods = require('./methods');
Run Code Online (Sandbox Code Playgroud)
我知道第一段代码 允许文件中的其余函数暴露给NodeJS应用程序,但我不明白它是如何工作的,或者行中的代码意味着什么.
做什么
exports和module.exports实际意味着什么?
我相信第二段代码允许文件中的函数访问methods,但同样,它是如何做到的.
基本上,这些神奇的词是什么:module和exports?