Instructions for the http.response.write method in node.js

  • 2020-05-05 10:52:08
  • OfStack

method description:

Sends the response content to the requested client.

Before response.end (), response.write () can be executed multiple times.

syntax:


response.write(chunk, [encoding])

parameter:

chunk        

                      is an buffer or string, Represents the sent content

encoding                           if chunk is a string, you need to specify encoding to indicate how it is encoded. The default is utf-8

Example:


var http = require('http');
http.createServer(function(req, res){
 res.writeHead(200, {'Content-type' : 'text/html'});
 res.write('<h1>Node.js</h1>');
 res.end('<p>Hello World</p>');
}).listen(3000);


Related articles: