Getting Started with Node.js
Node.js allows developers to run JavaScript outside the browser. It is widely used for backend development, APIs, and server-side applications.
In this guide, you will learn how to install Node.js, test the installation, use the REPL, and create your first server.
Installing Node.js
To start using Node.js, first install it on your computer.
Steps:
- Visit the official website:
https://nodejs.org
Download the LTS (Long Term Support) version
Run the installer and complete setup using default options
This installation works on:
Windows
macOS
Linux
Important:
Node.js installation automatically includes:
Node runtime
npm (Node Package Manager)
Checking Installation Using Terminal
After installation, open your terminal or command prompt.
Check Node.js version:
node -v
Example output:
v20.x.x
Check npm version:
npm -v
If both commands show version numbers, installation is successful.
Understanding Node REPL
REPL stands for:
Read
Eval
Print
Loop
It is an interactive environment where you can run JavaScript directly from the terminal.
Start REPL:
node
Example:
> console.log("Hello")
Hello
Another example:
> 10 + 20
30
Exit REPL:
.exit
Why REPL is Useful:
Test JavaScript quickly
Practice small snippets
Debug logic easily
Creating Your First JavaScript File
Create a new file named:
app.js
Add the following code:
console.log("Hello from Node.js");
Running Script Using Node Command
Open terminal in the project folder and run:
node app.js
Output:
Hello from Node.js
First Execution Flow:
app.js → Node Runtime → Code Executes → Output Appears
Node Execution Flow (Concept)
JavaScript File
↓
Node Runtime
↓
Executes Instructions
↓
Shows Result in Terminal
Writing a Hello World Server
Node.js includes a built-in module called http that allows you to create servers.
Example:
const http = require("http");
const server = http.createServer((req, res) => {
res.end("Hello World");
});
server.listen(3000, () => {
console.log("Server running on http://localhost:3000");
});
Running the Server
Save the file and run:
node app.js
Terminal Output:
Server running on http://localhost:3000
Now open your browser and visit:
http://localhost:3000
You will see:
Hello World
Script → Runtime → Output Flow
JavaScript File
↓
Node Runtime Starts
↓
Server Executes
↓
Browser Receives Response
Suggestions (Best Practices)
Use the LTS version of Node.js
Learn terminal basics alongside Node.js
Understand REPL before building projects
Practice running scripts multiple times
Keep early examples simple
Avoid frameworks like Express in the beginning
Focus on understanding core Node.js behavior
Conclusion
Node.js runs JavaScript outside the browser
Installation includes both Node and npm
REPL helps test JavaScript interactively
Scripts are executed using the
nodecommandNode.js can create servers using built-in modules
Learning these basics builds a strong foundation for backend development with Node.js.
