【发布时间】:2019-07-16 04:18:48
【问题描述】:
我使用 Winston 在控制台和应用程序中查看日志。如何创建 API 以在浏览器中查看我的 NodeJS 服务器的日志文件。
【问题讨论】:
标签: javascript node.js rest express
我使用 Winston 在控制台和应用程序中查看日志。如何创建 API 以在浏览器中查看我的 NodeJS 服务器的日志文件。
【问题讨论】:
标签: javascript node.js rest express
我假设您拥有由 winston 创建的日志文件。您可以编写如下 API:
app.get('/logs', function (req, res, next) {
var filePath = "path to your log file";
res.sendFile(filePath, function (err) {
if (err) {
next(err);
} else {
console.log('Sent the logs..');
}
});
});
【讨论】: