Node JS util返回:undefined

时间:2017-08-13 10:38:14

标签: node.js

我正在使用节点js模块util并将其包含在我的项目中,如下所示:

var util = require('util');

当我这样回复时:

util.inspect(response, false, null);

我得到了这个输出:

IncomingMessage {
  _readableState: 
   ReadableState {
     objectMode: false,
     highWaterMark: 16384,
     buffer: BufferList { head: null, tail: null, length: 0 },
     length: 0,
     text: "The ReadableState Description here",
     pipes: null,
     pipesCount: 0,
     flowing: true,
     ended: true,
     endEmitted: true,
     reading: false,
     sync: false,
     needReadable: false,
     emittedReadable: false,
     readableListening: false,
     resumeScheduled: false,
     defaultEncoding: 'utf8',
     ranOut: false,
     awaitDrain: 0,
     readingMore: false,
     decoder: null,
     encoding: null },
  readable: false,
  domain: 
   Domain {
     domain: null,
     _events: { error: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     members: [] },
  _events: 
....

现在,当我试图获得:

 response.IncomingMessage.ReadableState.text

我收到回复:

  

未定义

如何获取要输出的文本值?

1 个答案:

答案 0 :(得分:1)

不应该是:

response._readableState.text