1 min read

Node.js Response.WriteHead function

Up until now all we’ve been sending into the writeHead function is the status code.
However, it can take additional parameters like ‘Content-Length’, ‘Content-Type’.

 var http = require('http');  
 var fs = require('fs');  
 http.createServer(function(request, response) {  
  response.writeHead(200, {'Content-Type': 'text/html'} );  
  fs.readFile('index.html', function(err, contents) {  
   response.write(contents);  
   response.end();  
  });  
 }).listen(8080);  
Share your Love

Leave a Reply

Your email address will not be published. Required fields are marked *