Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

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

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.