有没有办法只记录对我的 nodejs 服务器所做的每个调用。从字面上看只是调用的 URL。我知道这是可能的,因为我曾在教程中看到过一个 super 简单的示例,但我不知道是在哪里看到的。
这是我正在寻找的一个蹩脚的例子:
app.listen(port, (call)=>{
console.log(call);
console.log(`Server running on http://localhost:${port}...`);
})
最佳答案
Is there a way to just log every call made to my nodejs server?
给你:https://github.com/expressjs/morgan
将所有请求以 Apache 组合格式记录到 STDOUT 的简单应用
var express = require('express')
var morgan = require('morgan')
var app = express()
app.use(morgan('combined'))
app.get('/', function (req, res) {
res.send('hello, world!')
})
关于node.js - Nodejs Express 记录每次调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52662010/