Tutorials References Exercises Videos NEW Menu
Paid Courses Website NEW

Node.js HTTP ServerResponse Object

❮ requestListener


Example

The ServerResponse object is passed as the second parameter in the requestListener function:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.write('Hello World!');
  res.end();
}).listen(8080);
Run example »

Definition and Usage

The ServerResponse object is passed as the second parameter to the requestListener function.

The ServerResponse object represents the writable stream back to the client.


ServerResponse Methods and Properties

addTrailers() Adds HTTP trailing headers
end() Signals that the the server should consider that the response is complete
finished Returns true if the response is complete, otherwise false
getHeader() Returns the value of the specified header
headersSent Returns true if headers were sent, otherwise false
removeHeader() Removes the specified header
sendDate Set to false if the Date header should not be sent in the response. Default true
setHeader() Sets the specified header
setTimeout Sets the timeout value of the socket to the specified number of milliseconds
statusCode Sets the status code that will be sent to the client
statusMessage Sets the status message that will be sent to the client
write() Sends text, or a text stream, to the client
writeContinue() Sends a HTTP Continue message to the client
writeHead() Sends status and response headers to the client

❮ requestListener