July 2017
Intermediate to advanced
402 pages
9h 38m
English
Now that 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/plain
response.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, or if you want to save time, download this from GitHub:
[ec2-user@ip-172-31-22-234 ~]$ wget http://bit.ly/2vESNuc -O /home/ec2-user/helloworld.js --2017-01-31 23:58:20-- http://bit.ly/2vESNuc Resolving bit.ly ...
Read now
Unlock full access