Setting Up Your First Node.js Application
Installing Node.js
Go to the official site: https://nodejs.org
Download the LTS (Long Term Support) version
Install with default settings (works for Windows, macOS, Linux)
OS-neutral tip:
If you can open a terminal/command prompt, you’re good to go
Installer automatically sets up everything
Checking Installation (Terminal)
Open terminal / command prompt and run:
node -v
You should see something like:
v20.x.x
Also check npm:
npm -v
Understanding Node REPL
REPL = Read → Evaluate → Print → Loop
It’s an interactive environment where you can run JavaScript line-by-line.
Start it:
node
Now you’ll see:
>
Try writing 2+3 in javascript:
Output:
5
What’s happening:
You type → Node reads → runs it → prints result → waits again
Exit REPL:
.exit
Creating Your First JavaScript File
Create an app.js file and write:
console.log("Hello from Node.js");
Running Script Using Node
In terminal: (write node .js)
node app.js
Output:
Hello from Node.js
Node Execution Flow
File (app.js)
↓
Node Runtime
↓
Executes JS
↓
Output in Terminal
Writing Your First "Hello World" Server
create server.js
const http = require('http');
const server = http.createServer((req, res) => {
res.send("Hello World");
});
server.listen(3000, () => {
console.log("Server running on port 3000");
});
Run it:
node server.js
Output:
Server running on port 3000
Open browser: Hit "http://localhost:3000"
You’ll see:
Hello World
