Running a Node.js Hello World application

Now that the node is installed, we can create a simple Hello World application. Here is the code for creating this:

var http = require("http") http.createServer(function (request, response) {// Send the HTTP header// HTTP Status: 200 : OK// Content Type: text/plainresponse.writeHead(200, {'Content-Type': 'text/plain'})// Send the response body as "Hello World" response.end('Hello World\n')}).listen(3000)// Console will print the message console.log('Server running')    

Feel free to copy this into a file. Alternatively, if you want to save time, download this from GitHub:

[ec2-user@ip-172-31-22-52 ~]$ wget https://raw.githubusercontent.com/yogeshraheja/Effective-DevOps-with-AWS/master/Chapter02/helloworld.js ...

Get Effective DevOps with AWS - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.