Getting Started with Node.js
Before building APIs or backend applications using Node.js, the first step is setting up the environment correctly.
Many beginners get confused between:
Node.js
JavaScript
terminal commands
REPL
So in this article, we will go step by step and understand how to start working with Node.js from scratch.
Installing Node.js
To use Node.js, you first need to install it on your system.
Go to the official website:
Download the LTS (Long Term Support) version because it is the most stable version for beginners.
The installation process is mostly straightforward:
download installer
run setup
complete installation
Node.js also installs:
- npm (Node Package Manager)
which is used later for installing libraries and packages.
Checking Installation Using Terminal
After installation, open your terminal or command prompt.
Run:
node -v
If Node.js is installed correctly, you will see the installed version.
Example:
v22.0.0
You can also check npm:
npm -v
This confirms both Node.js and npm are working properly.
Understanding Node REPL
REPL stands for:
Read
Evaluate
Print
Loop
It is an interactive environment where you can directly write and execute JavaScript code.
Start REPL using:
node
Now you can type JavaScript directly.
Example:
console.log("Hello")
Output:
Hello
REPL is useful for:
testing small code snippets
practicing JavaScript
quick debugging
To exit REPL:
.exit
Creating Your First JavaScript File
Create a file named:
app.js
Inside the file:
console.log("Hello from Node.js")
This is your first Node.js script.
Running Script Using Node Command
Open terminal in the same folder and run:
node app.js
Output:
Hello from Node.js
What happens here:
Node.js reads the file
V8 engine executes JavaScript
output appears in terminal
Writing Your First Hello World Server
Now let’s create a basic server.
Create a file:
const http = require("http")
const server = http.createServer((req, res) => {
res.end("Hello World")
})
server.listen(3000, () => {
console.log("Server running on port 3000")
})
Run it:
node app.js
Now open browser and visit:
http://localhost:3000
You will see:
Hello World
This is your first Node.js server.
Why This Matters
With just a few lines of code:
Node.js created a server
started listening for requests
sent a response to the browser
This is the foundation of backend development using JavaScript.
How to Think About Node.js Execution
Simple flow:
write JavaScript
Node.js runs the file
V8 engine executes the code
output is produced
One Line Summary
Node.js allows JavaScript code to run outside the browser using the Node runtime and V8 engine.
Conclusion
Setting up Node.js is the first step toward backend development using JavaScript.
Once installed, you can:
run JavaScript from terminal
test code using REPL
execute files
create servers
Understanding this basic workflow is important before moving to topics like modules, asynchronous programming, and Express.js.