What is Node.js?
Node.js lets you run JavaScript outside the browser. That's it. But that simple idea changed backend development forever.
JavaScript Everywhere
Before Node.js (2009), JavaScript only ran in browsers. If you wanted to build a backend, you needed Python, Ruby, Java, or PHP.
Now? One language for everything.
Frontend (React, Vue) → JavaScript
Backend (APIs, servers) → JavaScript (Node.js)
Scripts & tools → JavaScript (Node.js)
What Node.js Actually Is
Node.js is a runtime - software that executes JavaScript code.
- Browser runtime: Chrome, Firefox, Safari (has DOM, window, document)
- Node.js runtime: Your computer/server (has file system, network, OS access)
Same language, different superpowers:
| Browser JavaScript | Node.js |
|---|---|
| Manipulate DOM | Read/write files |
| Handle clicks | Create servers |
| Fetch from APIs | Connect to databases |
| localStorage | Access operating system |
See the Difference
In a browser (can't do this):// This would be a security nightmare in browsers
const fs = require('fs');
fs.readFile('/etc/passwd', 'utf8', (err, data) => {
console.log(data); // Reading system files!
});
In Node.js (totally fine):
const fs = require('fs');
fs.readFile('./myfile.txt', 'utf8', (err, data) => {
console.log(data); // Reading files is a core feature
});
Why Node.js Took Off
1. JavaScript developers could build backendsMillions of frontend devs could suddenly write server code without learning a new language.
2. npm - The largest package ecosystemOver 2 million packages. Need to send emails? npm install nodemailer. Parse dates? npm install dayjs. Almost everything is solved.
Node.js handles thousands of simultaneous connections efficiently. We'll cover this in the Event Loop lesson - it's a game-changer.
4. Companies adopted itNetflix, LinkedIn, Uber, PayPal, NASA - all use Node.js in production.
What You'll Build With Node.js
- REST APIs - The backend for web and mobile apps
- Real-time apps - Chat, live updates, gaming
- CLI tools - Scripts and developer tools
- Microservices - Small, focused services
Quick Check: Is Node.js Installed?
Open your terminal and run:
node --version
Expected output:
v20.10.0
(Your version may differ - anything v18+ is great)
If you see "command not found", download Node.js from [nodejs.org](https://nodejs.org).
Your First Node.js Command
Let's prove JavaScript runs outside the browser:
node -e "console.log('Hello from Node.js!')"
Output:
Hello from Node.js!
That console.log ran on your computer, not in a browser. Welcome to Node.js.
Key Takeaways
- Node.js = JavaScript runtime for servers and scripts
- Same JavaScript you know, different environment
- No DOM, but you get file system, network, OS access
- npm gives you millions of packages
- Non-blocking architecture handles many connections
Next, let's write and run your first Node.js script!