Node.js http response text content

Description

Node.js http response text content


var http = require("http");

var host = "127.0.0.1";
var port = 3000;/*  w  ww  .j ava2  s.  co m*/
var server = http.createServer(function(request, response){
  console.log("Received request: " + request.url);
  response.writeHead(200, {"Content-type":"text/plain"});
  response.end("Awesome! A simple node.js server.");

  // the other less elegant way
  //response.write("Hello world!");
  //response.end();
});

server.listen(port, host, function(){
  console.log("Listening " + host + ":" + port + "\n");
  console.log("Open your browser, http://localhost:3000");
});



PreviousNext

Related