Last Updated: February 25, 2016
·
451
· jeffscottward

Node Ch1 Learnings

Basic Hello World App

// Require HTTP Module from native Node Platform
var http = require('http');

// Create HTTP server with simple callback
// 200 means the request has succeeded. 
// Specify the Mime type so the browser understands what it is dealing with
// Write the response data
// End the response

http.createServer(function(request,response){
  response.writeHead(200, {'Content-Type':'text/plain'});
  response.write('Hello World\n');
  response.end();
});

// Tell the server to start with the port 3000
server.listen(3000);

// Log out to the terminal for the user to go to the correct address
console.log('Server running at http://localhost:300');