update tutorial sistema para operativo node instalar framework ejemplos actualizar node.js documentation request

tutorial - Node.js solicitud de documentación del objeto?



sistema operativo para node js (3)

Esta es una pregunta bastante directa, pero no he encontrado nada en Google. Estoy buscando documentación sobre el parámetro de solicitud en la función de servidor de creación de Node.js, pero no he podido encontrar nada.

http.createServer(function(request, response){ console.log(JSON.stringify(request)); });

La depuración con JSON.stringify () me da un error, que el objeto es circular y el programa se detiene. He visto diferentes cosas como request.url o request.body , pero ¿hay una página que documente todas las funciones y parámetros de solicitud? Parece que debería ser fácil de encontrar, simplemente no puedo encontrarlo.

Lo intenté de nuevo, y resulta que solo hace console.log(request) escribe todos los datos de la solicitud. Aquí es solo como una referencia:

ondata: [Function], _httpMessage: { domain: null, _events: [Object], _maxListeners: 10, output: [], outputEncodings: [], writable: true, _last: false, chunkedEncoding: false, shouldKeepAlive: true, useChunkedEncodingByDefault: true, sendDate: true, _hasBody: true, _trailer: '''', finished: false, _hangupClose: false, socket: [Circular], connection: [Circular] } }, connection: { _connecting: false, _handle: { fd: null, writeQueueSize: 0, owner: [Circular], onread: [Function: onread], reading: true }, _readableState: { highWaterMark: 16384, buffer: [], length: 0, pipes: null, pipesCount: 0, flowing: false, ended: false, endEmitted: false, reading: true, calledRead: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, objectMode: false, defaultEncoding: ''utf8'', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null }, readable: true, domain: null, _events: { end: [Object], finish: [Function: onSocketFinish], _socketEnd: [Function: onSocketEnd], drain: [Function: ondrain], timeout: [Function], error: [Function], close: [Object] }, _maxListeners: 10, _writableState: { highWaterMark: 16384, objectMode: false, needDrain: false, ending: false, ended: false, finished: false, decodeStrings: false, defaultEncoding: ''utf8'', length: 0, writing: false, sync: true, bufferProcessing: false, onwrite: [Function], writecb: null, writelen: 0, buffer: [] }, writable: true, allowHalfOpen: true, onend: [Function], destroyed: false, errorEmitted: false, bytesRead: 357, _bytesDispatched: 0, _pendingData: null, _pendingEncoding: '''', server: { domain: null, _events: [Object], _maxListeners: 10, _connections: 1, connections: [Getter/Setter], _handle: [Object], _usingSlaves: false, _slaves: [], allowHalfOpen: true, httpAllowHalfOpen: false, timeout: 120000, _connectionKey: ''4:0.0.0.0:1337'' }, _idleTimeout: 120000, _idleNext: { _idleNext: [Circular], _idlePrev: [Circular], msecs: 120000, ontimeout: [Function: listOnTimeout] }, _idlePrev: { _idleNext: [Circular], _idlePrev: [Circular], msecs: 120000, ontimeout: [Function: listOnTimeout] }, _idleStart: 1371952289619, parser: { _headers: [], _url: '''', onHeaders: [Function: parserOnHeaders], onHeadersComplete: [Function: parserOnHeadersComplete], onBody: [Function: parserOnBody], onMessageComplete: [Function: parserOnMessageComplete], socket: [Circular], incoming: [Circular], maxHeaderPairs: 2000, onIncoming: [Function] }, ondata: [Function], _httpMessage: { domain: null, _events: [Object], _maxListeners: 10, output: [], outputEncodings: [], writable: true, _last: false, chunkedEncoding: false, shouldKeepAlive: true, useChunkedEncodingByDefault: true, sendDate: true, _hasBody: true, _trailer: '''', finished: false, _hangupClose: false, socket: [Circular], connection: [Circular] } }, httpVersion: ''1.1'', complete: false, headers: { host: ''localhost:1337'', connection: ''keep-alive'', ''cache-control'': ''max-age=0'', accept: ''text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'', ''user-agent'': ''Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36'', ''accept-encoding'': ''gzip,deflate,sdch'', ''accept-language'': ''en-US,en;q=0.8,ja;q=0.6'' }, trailers: {}, _pendings: [], _pendingIndex: 0, url: ''/'', method: ''GET'', statusCode: null, client: { _connecting: false, _handle: { fd: null, writeQueueSize: 0, owner: [Circular], onread: [Function: onread], reading: true }, _readableState: { highWaterMark: 16384, buffer: [], length: 0, pipes: null, pipesCount: 0, flowing: false, ended: false, endEmitted: false, reading: true, calledRead: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, objectMode: false, defaultEncoding: ''utf8'', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null }, readable: true, domain: null, _events: { end: [Object], finish: [Function: onSocketFinish], _socketEnd: [Function: onSocketEnd], drain: [Function: ondrain], timeout: [Function], error: [Function], close: [Object] }, _maxListeners: 10, _writableState: { highWaterMark: 16384, objectMode: false, needDrain: false, ending: false, ended: false, finished: false, decodeStrings: false, defaultEncoding: ''utf8'', length: 0, writing: false, sync: true, bufferProcessing: false, onwrite: [Function], writecb: null, writelen: 0, buffer: [] }, writable: true, allowHalfOpen: true, onend: [Function], destroyed: false, errorEmitted: false, bytesRead: 357, _bytesDispatched: 0, _pendingData: null, _pendingEncoding: '''', server: { domain: null, _events: [Object], _maxListeners: 10, _connections: 1, connections: [Getter/Setter], _handle: [Object], _usingSlaves: false, _slaves: [], allowHalfOpen: true, httpAllowHalfOpen: false, timeout: 120000, _connectionKey: ''4:0.0.0.0:1337'' }, _idleTimeout: 120000, _idleNext: { _idleNext: [Circular], _idlePrev: [Circular], msecs: 120000, ontimeout: [Function: listOnTimeout] }, _idlePrev: { _idleNext: [Circular], _idlePrev: [Circular], msecs: 120000, ontimeout: [Function: listOnTimeout] }, _idleStart: 1371952289619, parser: { _headers: [], _url: '''', onHeaders: [Function: parserOnHeaders], onHeadersComplete: [Function: parserOnHeadersComplete], onBody: [Function: parserOnBody], onMessageComplete: [Function: parserOnMessageComplete], socket: [Circular], incoming: [Circular], maxHeaderPairs: 2000, onIncoming: [Function] }, ondata: [Function], _httpMessage: { domain: null, _events: [Object], _maxListeners: 10, output: [], outputEncodings: [], writable: true, _last: false, chunkedEncoding: false, shouldKeepAlive: true, useChunkedEncodingByDefault: true, sendDate: true, _hasBody: true, _trailer: '''', finished: false, _hangupClose: false, socket: [Circular], connection: [Circular] } }, _consuming: false, _dumped: false, httpVersionMajor: 1, httpVersionMinor: 1, upgrade: false }


Estoy de acuerdo con Delio, el objeto Request es del tipo objeto IncomingMessage, que es creado por http.ClientRequest.


No estoy seguro de si esta es una respuesta correcta, ya que me parece sencilla, pero ¿echó un vistazo a http://nodejs.org/api/http.html#http_http_incomingmessage ?

La solicitud es una instancia del objeto anterior. Por cierto, si realmente quieres ver lo que hay dentro de ese objeto con "fuerza bruta", no debes analizarlo, ya que no será una cadena JSON, sino que debes hacer algo como:

for (i in request) { //Your code here }

Espero eso ayude.


Solo para agregar, como novato relativo en Node.js, encuentro confuso que cada marco tenga su propia implementación de un objeto de "solicitud".

Por ejemplo,

Express: http://expressjs.com/api.html#req.param

y

Hapi: http://spumko.github.io/resource/api/#request-object (solo para observar que el objeto de solicitud sin procesar todavía está disponible en request.raw.req)

Algunas bibliotecas asumen la presencia del método Express '''' req.param '''' y fallan cuando se usan en proyectos que no son Express.