node.js - 为什么在下面的示例中命名中间件
问题描述
我正在从以下链接http://expressjs.com/en/guide/routing.html阅读有关路由器的文档
var express = require('express')
var router = express.Router()
// middleware that is specific to this router
router.use(function timeLog (req, res, next) { //why is the middle ware named here
console.log('Time: ', Date.now())
next()
})
// define the home page route
router.get('/', function (req, res) {
res.send('Birds home page')
})
// define the about route
router.get('/about', function (req, res) {
res.send('About birds')
})
module.exports = router
我怀疑(检查代码中的注释)为什么在 router.use(.....) 中间件被命名为 ie。它命名为timeLog,而通常我们不会在中间件中写名字,而是直接写函数(req,res)..我是这个领域的初学者,所以我可能会问一些明显的问题..但无论如何提前谢谢。
解决方案
推荐阅读
- python - 主列表中重复段的总和
- jenkins - 通过 Jenkinsfile 将图像标签 docker-compose 替换为 sed 命令
- yaml - 如何在 ARM 模板中为 AppService appsettings 设置动态数组
- c# - 在 asp.net 中的 c#.net 中将多变量从字符串转换为十进制引发了“System.FormatException”类型的异常
- sql-server - 将“1994 年 10 月 14 日”字符串转换为 SQL 日期列类型
- awk - 使用 grep/awk/sed 在某个单词之后对整个文本进行 grep
- spring-batch - Spring Batch - 使用远程分区/远程分块时 CPU 利用率高
- flask - 如何动态创建 SQLAlchemy 引擎并在 Flask 中的请求之间使用它?
- amazon-s3 - yace 在 grafana 中不显示任何数据
- mysql - mysql:如何根据其他列对列进行排序