Setting Up Your First Node.js Application Step-by-Step
When people first hear about Node.js, they usually think:
“It lets JavaScript run outside the browser.”
And that’s exactly what it does.
Node.js is a JavaScript runtime that allows you to:
build servers
create APIs
work with files
build backend applications
Before building large applications, it’s important to understand how a basic Node.js setup works from the ground up.
This article walks through:
installing Node.js
verifying installation
understanding the Node REPL
running JavaScript files
creating your first server
without using any frameworks.
What Is Node.js?
Normally, JavaScript runs inside browsers.
Example:
Chrome
Firefox
Edge
Node.js allows JavaScript to run directly on your computer using the V8 JavaScript engine.
This means JavaScript can now:
access files
create servers
interact with operating system resources
That’s what makes backend development possible with JavaScript.
Installing Node.js
The easiest way to install Node.js is from the official website.
You’ll usually see:
LTS (Long Term Support)
Current version
For beginners, LTS is generally preferred because it is more stable.
What Gets Installed?
Installing Node.js usually installs:
Node.js runtime
npm (Node Package Manager)
npm is used later for installing libraries and packages.
Checking the Installation
After installation, open your terminal and run:
node -v
Example output:
v24.15.0
This confirms Node.js is installed successfully.
Checking npm
You can also verify npm:
npm -v
Example:
11.11.0
Understanding the Node REPL
Before creating files, Node.js provides something called:
REPL
REPL stands for:
Read
Evaluate
Print
Loop
It is an interactive environment where you can run JavaScript directly from the terminal.
Starting the REPL
Run:
node
You’ll see something like:
>
Now you can execute JavaScript instantly.
Example:
2 + 2
Output:
4
Why the REPL Exists
The REPL is useful for:
quick testing
experimenting
debugging small snippets
learning JavaScript behavior
Instead of creating files every time, you can test code immediately.
Exiting the REPL
You can exit using:
.exit
or:
Ctrl + C
twice.
Creating Your First JavaScript File
Now let’s create an actual Node.js application.
Create a file named:
app.js
Inside it:
console.log("Hello Node.js");
Running the Script
Inside the terminal, run:
node app.js
Output:
Hello Node.js
What Actually Happened?
Flow:
app.js
↓
Node.js runtime reads file
↓
JavaScript executes
↓
Output printed in terminal
Node.js acts as the environment executing your JavaScript code.
Understanding the node Command
This command:
node app.js
basically tells Node.js:
“Execute this JavaScript file.”
Unlike browsers, Node.js runs code directly on your machine.
Writing Your First Node.js Server
Now let’s create a basic HTTP server.
Replace your code with:
const http = require("http");
const server = http.createServer((req, res) => {
res.end("Hello from Node.js server");
});
server.listen(3000, () => {
console.log("Server running on port 3000");
});
Running the Server
Run:
node app.js
Output:
Server running on port 3000
Now open:
http://localhost:3000
You’ll see:
Hello from Node.js server
Understanding What Happened
Let’s break it down.
Step 1: Import HTTP Module
const http = require("http");
Node.js includes built-in modules for backend functionality.
The http module helps create web servers.
Step 2: Create Server
http.createServer()
This creates a server capable of handling browser requests.
Step 3: Handle Requests
(req, res) => {}
req→ incoming requestres→ outgoing response
Whenever someone visits the server, this function runs.
Step 4: Send Response
res.end("Hello from Node.js server");
This sends data back to the browser.
Step 5: Start Listening
server.listen(3000)
This starts the server on port 3000.
Now Node.js continuously waits for incoming requests.
What Is localhost?
localhost refers to:
your own computer
local development machine
Example:
http://localhost:3000
means:
“Access port 3000 on this machine.”
Simple Mental Model
Think of Node.js like this:
JavaScript File
“Instructions.”
Node Runtime
“Engine executing those instructions.”
HTTP Server
“Program waiting for browser requests.”
Full Flow
Browser request
↓
Node.js server receives request
↓
Request handler executes
↓
Response sent back
↓
Browser displays output
Your first Node.js application is actually very small:
install Node.js
write a JavaScript file
execute it using Node
optionally create an HTTP server
But this tiny setup is the foundation for:
APIs
backend systems
real-time apps
full-stack applications
The most important realization is:
Node.js is simply JavaScript running outside the browser with access to backend capabilities.
Once you understand:
the runtime
the REPL
script execution
server creation
the entire Node.js ecosystem becomes much easier to learn.