Posts

Showing posts from December, 2017

My first Node.JS Code

Firstly I created a file called: main.js  The first line I wrote was the http library being called to the file. This standard http library allows me to make http.createServer function later on for me to listen to a port 8080 for any requests. I wrote a variable called "body" and added a string of text that I want to show on when I accessed localhost:8080 on the web browser. The res.writeHead(...) function, available as a local library of Nodejs, allowed me to write some file headers that will be showned when I run the curl -i command later. Content-Length and Content-Type are the header information that I add to the webpage. There are many header variables that we can add which I will describe in detail in other posts. The 200 server response code passed in res.writeHead(..,..) first argument is a success response code. var http = require('http'); function process_request(req, res) {         var body = "This is the body of a Javascript code.";...