Setting Up Your First Node.js Application Step-by-Step
What Is Node.js?
Node.js allows JavaScript to run outside the browser.
It is commonly used for:
Backend development
APIs
Servers
CLI tools
Step 1: Install Node.js
Download Node.js from:
Install the LTS version.
Step 2: Verify Installation
Open terminal and run:
node -v
Example Output
v22.1.0
Check npm Installation
npm -v
What Is npm?
npm = Node Package Manager
Used to install JavaScript packages.
Step 3: Understanding Node REPL
REPL means:
It is an interactive Node.js console.
Start REPL
node
Example
> 2 + 3
Output
5
Another Example
> console.log("Hello")
Output
Hello
Exit REPL
.exit
or press:
Ctrl + C twice
Step 4: Create Your First JavaScript File
Create a file:
app.js
Add Code
console.log("Hello Node.js");
Step 5: Run the Script
Open terminal in project folder.
Run:
node app.js
Output
Hello Node.js
Node Execution Flow
Script → Runtime → Output Flow
Step 6: Create Your First Node.js Server
Node.js includes a built-in HTTP module.
Hello World Server
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 Server
node app.js
Output
Server running on port 3000
Open Browser
Visit:
http://localhost:3000
Browser Result
Hello World
How the Server Works
Server Request Flow
Stopping the Server
Press:
Ctrl + C
inside terminal.
Common Beginner Mistakes
Practice Exercise
Create math.js
console.log(10 + 5);
Run File
node math.js
Create Another Server
const http = require("http");
http.createServer((req, res) => {
res.end("My First Server");
}).listen(4000);
Visit:
http://localhost:4000
Key Takeaways
Final Notes
Your first Node.js application teaches the core workflow:
Write JavaScript ↓ Run with Node.js ↓ See output/server response
This foundation is important before learning:
Express.js
APIs
Databases
Authentication
Real-world backend systems
No attachments.
0 Comments
Sign in to join the conversation
No comments yet. Be the first to comment!