Learn Node.js and build hello world example from scratch
Table of Contents
I have been thinking about learning Node.js for a ages now (at least a few years now), but somehow or other procrastinated on this (noble) thought till now.
Finally, when I was searching a new topic for my YouTube channel, I took up this seemingly arduous task (till now) of learning as well as teaching Node.js (honestly if you are a beginner with this JS runtime and are in the same boat as myself, you may still find it of some value)
In this post, I shall take up the Node.js fundamentals, features of Nodejs and come up with building a Hello World example step by step using Node.js
YouTube version:
So :
What is this buzz about Nodejs?
- Node.js is an open-source and cross-platform JavaScript runtime environment on the server.
- Node.js runs the V8 JavaScript engine, the core of Google Chrome, outside of the browser.
- Node.js uses asynchronous programming!
Node.js – Some Features
- An event driven runtime, it is designed to build scalable network applications
- Many connections can be handled concurrently as in the “hello world” example shown in the next slide
- Upon each connection when activated, the callback is fired
- If there is no work to be done, Node.js will sleep
What can Nodejs do ?
I may say here that Node.js and Nodejs are both acceptable and are used interchangeably as Node is afterall a JS runtime.
Some of the things that Nodejs can do are:
- Can create, open, read, write, delete and close files on the server
- Generate dynamic page content, where the page presents different content for different logged in users while maintaining the same page layout
- It can do CRUD operations on databases
- Nodejs can also collect form data
- Node.js is employed in real-time web applications employing push technology over websockets. It is ideal for chat applications
- Nodejs helps build web applications with real-time, two-way connections, where both the client and server can initiate communication, allowing them to exchange data freely.
Download and Install Node
You can download Node.js from the official Node.js website https://nodejs.org/
It is easy to install Nodejs after download by double-clicking and following the wizard steps in the installer. The installation instructions are available at the website as well.
Hello World Application
Let us now switchover to Visual Studio code IDE which is my preferable code IDE with all the great features of accepting extensions for various tasks like:
.NET Extension Pack
- .NET Extension Pack
- C#
- Docker
- Extension Pack for Java and many more
Create a folder named “Node” within my D:\Projects directory directly from the terminal window in Visual Studio Code by giving the mkdir command as in the fig 1 below

Now create a new file Hello.js within the Node directory on the Explorer tab (on the left) by clicking the new file icon and writing the file name “Hello.js” in the text box.
Complete the code in the Hello.js file as below
const res = require('express/lib/response');
const http = require('http');
const hostname = 'localhost';
const port = 3000;
const server = http.createServer((req, res)=>{
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.write('Hello World from Node');
res.end();
});
server.listen(port, hostname, ()=>{
console.log(`Server running at http://${hostname}:${port}/`)
});
The line 1 calls the built in module for the response using the require keyword
The next line (line 2) then calls the http (Hyper Text Transfer Protocol) module which helps in transferring data over the web.
Application then creates variables to hold the hostname and port number.
In the code snippet below :
const server = http.createServer((req, res)=>{
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.write('Hello World from Node');
res.end();
The createServer method called on the http module, creates a server. It also takes a request and a response parameter and sets the 200OK status code for the response. The response calls the setHeader method to set the header with the content type and writes some data to the stream. Server listens on the host port for the incoming request.
To run the application, open a Windows command prompt and type as follows (after changing to your work directory. Fig 2)

You can see that the server is running at port : 3000
Now open the Chrome browser (or any other that you are used to) and type http://localhost:3000 and you’ll see the following message: (Fig 3)

Success. Wow, that’s what we set out to do!!
Follow Me Here