Node.js Introduction

What Is Node.js?
Node.js is an open-source JavaScript runtime that runs on servers and desktops—not in a browser. It uses Google’s V8 engine and an event-driven, non-blocking I/O model built for APIs, real-time apps, and tools.
JavaScript = the language
Node.js = the runtime outside the browser
Stack pieces:
V8 engine → runs your JS
libuv → async I/O & event loop
npm → packages & scripts Ryan Dahl created Node.js in 2009 so developers could use one language on both the client and the server. Today it powers backends, CLIs, build tools, and full-stack frameworks.
Why Use Node.js?
Browsers already run JavaScript. Node lets the same language handle files, networks, and processes on the server.
| Need | How Node.js helps |
|---|---|
| One language end-to-end | Share JS skills between front end and back end |
| Fast I/O APIs | Non-blocking model handles many connections well |
| Huge ecosystem | npm packages for almost any library or tool |
| Real-time features | WebSockets, chat, and live dashboards |
How Node.js Handles Work
Requests and I/O go through the event loop instead of blocking one thread per connection:
| Step | What happens |
|---|---|
| 1. Start | You run node app.js; V8 loads your script |
| 2. Register | Your code sets up servers, timers, and callbacks |
| 3. Event loop | Node waits for I/O; when ready, it runs the callback |
| 4. Respond | Your handler sends a response or continues the work |
Install, Hello World & First Server
Download the LTS build from nodejs.org, then verify:
node -v
npm -v
node hello.js console.log('Hello World'); Hello World HTTP server
const http = require('http');
const server = http.createServer((request, response) => {
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end('Hello World\n');
});
server.listen(8080, () => {
console.log('Server running at http://127.0.0.1:8080/');
}); How It Works
1. Module. require('http') loads Node’s built-in HTTP module.
2. Create. createServer registers a callback for each request.
3. Listen. listen(8080) starts the server; open the URL in a browser.
Next, build apps faster with Express.
Node.js vs Browser JavaScript
Same language, different environment and APIs:
| Node.js | Browser |
|---|---|
| Runs on servers & desktops | Runs in the user’s browser |
Has fs, http, path, process | Has DOM, window, document |
Modules via require / import | Scripts and ES modules in pages |
| No built-in UI | Renders HTML and CSS |
When to use which
| Use Node when… | Use the browser when… |
|---|---|
| You build APIs, CLIs, or file tools | You update the page or handle UI events |
| You need server secrets and databases | You need DOM, canvas, or Web APIs |
| You run build tools (Vite, webpack, …) | You ship front-end code to users |
Core Building Blocks
These pieces show up in almost every Node project:
| Concept | What it does |
|---|---|
| Runtime | Executes JS with V8 outside the browser |
| Modules | require() (CommonJS) or import (ESM) |
| npm | Installs packages and runs project scripts |
package.json | Project metadata and dependencies |
| Built-ins | fs, path, http, url, os |
| Event loop | Schedules async callbacks without blocking |
Where Is Node.js Used?
Node shows up across modern JavaScript stacks:
| Use case | Why Node.js fits |
|---|---|
| REST / GraphQL APIs | JSON in and out with Express, Fastify, Nest, … |
| Real-time apps | Chat, notifications, collaborative tools |
| Full-stack JS | Same language for React/Vue front ends and the API |
| CLIs & tooling | npm scripts, bundlers, linters, generators |
| Microservices | Lightweight HTTP services that scale with I/O |
| Serverless | AWS Lambda, Azure Functions, and similar runtimes |
Key Takeaways
- Node.js runs JavaScript outside the browser with V8.
- Start with
node file.js, then try thehttpmodule. - npm installs packages;
package.jsontracks them. - Next step: frameworks like Express add routing and middleware.
One line: Node.js brings JavaScript to the server—next, learn Express.
Frequently Asked Questions
Did you know?
Node.js runs JavaScript outside the browser using the V8 engine. Install from nodejs.org, run scripts with node file.js, and manage packages with npm install.
Next: Express Introduction
Add routing and middleware on top of Node’s HTTP server.
12 people found this page helpful
