Learning Intentions
- Understand the basics of Node.js, its purpose, and how it works with an event-driven and non-blocking architecture.
- Set up a Node.js development environment, including installation and creating a simple “Hello World” application.
- Explore the Node.js REPL to perform basic programming tasks like arithmetic operations, string manipulation, and array handling.
Syllabus Outcome
SE-12-02 applies structural elements to develop programming code
Lesson Activity
Learning Node.js
What is Node.js?
Node.js is an open-source, cross-platform JavaScript runtime environment that allows developers to run JavaScript code outside a web browser. It was created by Ryan Dahl in 2009 with the goal of extending the use of JavaScript to the back-end, enabling developers to use the same language for both front-end and server-side programming. Before Node.js, JavaScript was mainly used for making websites interactive in the browser, but now it can be used to create full-stack applications.
History:
Node.js came about when developers wanted a more efficient way to handle real-time applications, such as chat systems, without having to rely on traditional server-side languages like PHP. Dahl noticed inefficiencies in how web servers handled concurrent requests, leading him to create Node.js, which uses Google Chrome’s V8 JavaScript engine to execute code quickly and efficiently.
Usage:
Node.js is now used by companies around the world, including Netflix, Uber, and LinkedIn, to power their high-performance applications. It’s especially popular for building things like web servers, real-time apps (like messaging or gaming platforms), APIs, and data-heavy applications. One of its main advantages is that it uses JavaScript throughout, making it easier for developers to work on both the front and back-end of web applications.
Importance:
The key to Node.js’ success is its ability to handle thousands of simultaneous requests with minimal resources. This is achieved through its non-blocking I/O and event-driven architecture. Additionally, Node.js has a massive collection of modules and tools available through the npm (Node Package Manager), which allows developers to quickly add functionality to their projects. By using JavaScript everywhere (front-end and back-end), it simplifies the development process and speeds up the creation of applications.
How Node.js Works
Node.js works using two key principles: event-driven architecture and non-blocking I/O, which together make it very efficient at handling multiple tasks at the same time without slowing down.
Event-Driven Architecture:
In traditional systems, a web server waits for a task (such as reading a file) to finish before moving on to the next one. This causes delays and wastes resources. However, Node.js uses an event-driven model, meaning it doesn’t wait for one task to finish before starting the next. Instead, when an event occurs (like a request to read a file), it is registered and Node.js continues to process other requests. Once the event is ready (such as the file being read), Node.js will execute the appropriate callback function to handle the response. This is especially useful in real-time applications where many tasks happen at once.
Non-Blocking I/O:
Another advantage of Node.js is its non-blocking input/output operations. In most programming environments, when you request to read or write data (like accessing a database), the system stops and waits for that operation to finish before continuing. Node.js, however, doesn’t stop; it performs these tasks in the background, allowing other operations to happen in the meantime. This is why Node.js can handle many tasks at once, even with a single thread, making it much faster and more efficient for high-traffic applications.
In short, Node.js’ ability to handle thousands of concurrent connections, without creating multiple threads, makes it ideal for apps that require real-time communication or need to handle large volumes of requests quickly.
NPM (Node Package Manager)
Before we dive into the installation of Node.js, it’s important to understand what npm is and why it’s essential. npm, which stands for Node Package Manager, is a tool that comes automatically with Node.js. It allows developers to easily manage and install reusable JavaScript code libraries (called packages or modules) in their projects. Whether you need a specific framework like Express to build a web server or a tool for managing real-time data, npm helps you find and include these packages with just a few commands.
By using npm, developers save time because they don’t need to write everything from scratch. It also ensures that all project dependencies are handled efficiently through a file called package.json
, which keeps track of the necessary libraries and their versions. This way, anyone working on a project can install all required packages in one go.
Source: GeeksforGeeks Node JS NPM
Installing Node.js

Install Node.js and npm on Windows
Node.js comes with npm, so by installing Node.js, npm is also installed automatically.
For Windows:
- Visit the official Node.js website.
- Download the Windows Installer (choose the LTS version for stability).
- Open the
.msi
file and follow the installation steps.- Accept the terms in the license agreement.
- Choose the destination folder (default is fine).
- Make sure to select “Add to PATH” in the setup wizard to enable you to run
node
andnpm
commands from any directory.
- To check if Node.js and npm were installed correctly:
- Open the Command Prompt (search for “cmd” in the Start menu).
node -v
npm -v
This should return the version numbers of both Node.js and npm. For Example:
C:\node -v
v22.8.0
C:\npm -v
10.8.3

Install Node.js and npm on Mac
Node.js comes with npm, so by installing Node.js, npm is also installed automatically.
For Mac:
- Visit the official Node.js website.+
- Download the macOS Installer (again, the LTS version is recommended).
- Open the
.pkg
file and follow the installation instructions. - After installation, open the Terminal (search for “Terminal” in Spotlight or Finder).
- Check the installation by typing:
node -v
npm -v
You should see the version numbers of both Node.js and npm. I don’t own a mac, but I assume the output is the same as windows.
Creating a Basic Node.js Application (“Hello World”)
Now that Node.js and npm are installed, let’s create a simple Node.js application.
Steps:
- Open a Terminal (Mac) or Command Prompt (Windows).
- Navigate to a folder where you want to create your project. For example in Windows:
cd Desktop
- Create a new directory for your project and navigate into it:
mkdir NodeTutorial
cd NodeTutorial
- Create a file named
app.js
by using VS Code from the command prompt:
code app.js
- In app.js, write the following simple Node.js program:
// app.js
console.log('Hello, World!');
- To run your application, return to the terminal or command prompt, make sure you’re still in the NodeTutorial directory, and execute:
node app.js
You should see the message “Hello, World!” printed in the terminal.
Exploring the Node.js REPL (Read-Eval-Print-Loop)
The Node.js Read-Eval-Print-Loop (REPL) is an interactive shell that processes Node.js expressions. The shell reads JavaScript code the user enters, evaluates the result of interpreting the line of code, prints the result to the user, and loops until the user signals to quit.
The REPL is bundled with every Node.js installation and allows you to quickly test and explore JavaScript code within the Node environment without having to store it in a file.
Source: How To Use the Node.js REPL
- Open a Terminal (Mac) or Command Prompt (Windows).
- Simply type node and press Enter. This will start the Node.js REPL environment.
- You’ll see the REPL prompt: >
- You can now enter JavaScript commands, and they will be executed immediately. Try the following:
console.log("Hello from REPL");
The REPL will immediately evaluate the command and print the result.
- You can also perform calculations, define variables, and create small functions:
let x = 10;
x * 5;
- To exit the REPL, simply type
.exit
or pressCtrl + C
twice.
Node.js REPL Activities
You will be familiar with some of these already with your previous lesson on JavaScript.
Basic Arithmetic and Variables
let a = 7;
let b = 3;
a + b; // 10
a * b; // 21
a / b; // 2.333...
String Manipulation
let greeting = "Hello";
greeting + " there!"; // "Hello there!"
greeting.toUpperCase(); // "HELLO"
Arrays
let fruits = ["apple", "banana", "cherry"];
fruits.push("orange"); // Add an item
fruits[1]; // Access an item: "banana"

Next lesson we will be looking at ‘Working with Modules, File Systems, and HTTP’.