What does GET /bla - - ms - - mean in NodeJs console?

丶灬走出姿态 提交于 2021-01-27 07:52:52

问题


When I go to the page /bla in my NodeJS app, the console prints out

GET /bla - - ms - -

In words (for easier Google searches), dash dash ms dash dash.

What does this mean?


回答1:


This is the output from morgan, a HTTP request logger middleware for node.js.

It logs all requests, by default, to the console. Depending on your configurations it will display different data from the request.

If you are using the default format (dev), the data displayed is:

:method :url :status :response-time ms - :res[content-length]



回答2:


According to this thread:

The log line GET / - - ms - - is the dev format saying you never sent a response before Node.js killed the TCP connection for idling too long.

So the problem is a request that wasn't responded by the route - in other words, some middleware along the route never called next(), res.send(), res.end() or any other equivalent means to respond.

After some testing, I realized that this can also occur if the route doesn't handle the client aborting the request (can be easily tested by e.g making the request through a browser and clicking on the X button before it's done).

According to the docs, the way to handle that would probably be something like (note - wasn't tested):

req.on('abort', function (err) {
   if (err)
       console.error(error.message);

   // your code here
});


来源:https://stackoverflow.com/questions/29077355/what-does-get-bla-ms-mean-in-nodejs-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!