How I wish there was a documentation that shows me a detailed explanation of what's happening in a Hello World example.

Well. Instead of wishing, I started to craft a nice visual for my own and I hope this would help others as well.

Some basic explanations:

What is Node.js?

  • An open source server environment.
  • It allows you to run JavaScript on the server.

Node.js uses asynchronous programming

  • generate dynamic page content
  • create, open, read, write, delete, and close files on the server
  • collect form data
  • add, delete, and modify data in your database

image-150
HTTP Server

image-151
function and parameters req and res

image-152
Status code

image-153
Content-Type

image-154
Finishing the request

image-155
Listening to the port

Things you need to run this on your machine:

  1. Install VSCode: https://code.visualstudio.com/.
  2. Install Node.js: https://nodejs.org/en/.
  3. Create a file named app.js.
  4. Copy the code below.
  5. In your terminal, execute node app.js.
  6. In your browser, type http://localhost:8080/ and hit Enter.
var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World!');
}).listen(8080);
app.js

References:

https://www.w3schools.com/nodejs/default.asp

https://nodejs.org/api/http.html