Название должно быть довольно само собой разумеющимся.
В целях отладки я хотел бы выразить, чтобы напечатать код ответа и тело для каждого обслуживаемого запроса. Печать кода ответа достаточно проста, но печать тела ответа сложнее, так как кажется, что тело ответа не доступно в качестве свойства.
Не работает следующее:
var express = require('express');
var app = express();
// define custom logging format
express.logger.format('detailed', function (token, req, res) {
return req.method + ': ' + req.path + ' -> ' + res.statusCode + ': ' + res.body + '\n';
});
// register logging middleware and use custom logging format
app.use(express.logger('detailed'));
// setup routes
app.get(..... omitted ...);
// start server
app.listen(8080);
Конечно, я мог бы легко распечатать ответы на клиенте, который отправил запрос, но я бы предпочел делать и на стороне сервера.
PS: Если это помогает, все мои ответы - json, но, надеюсь, есть решение, которое работает с общими ответами.