A comprehensive, hands-on learning resource for mastering Node.js core concepts. This repository contains practical, runnable examples that cover the essential building blocks every Node.js developer needs to understand—from the event loop and asynchronous patterns to file systems, HTTP servers, streams, and event handling.
This is a learning tutorial, not a production project. Each file is a standalone example designed to teach a specific Node.js concept. The files are organized sequentially and can be run individually to explore how different Node.js APIs and patterns work in isolation.
Whether you're new to Node.js or strengthening your fundamentals, this tutorial provides clear, runnable code that demonstrates core concepts through practice.
- Globals & Default Exports (
1-default.js,2-globals.js) — Understanding Node's global objects and module exports - CommonJS Modules (
3--modules.js,5-utils.js,6-alternative.js) — How to structure code with require/exports - Path & OS Modules (
8-OS-module.js,9-path-module.js) — Working with file paths and operating system info
- Synchronous File I/O (
10-fs-sync-module.js) — Reading and writing files in a blocking manner - Asynchronous File I/O (
11-fs-async-module.js) — Non-blocking file operations - Understanding Async Behavior — See the difference and when to use each approach
- Event Loop Fundamentals (
1-event-loop-examples/1-read-file.js) — How Node.js handles async operations - Timers (
1-event-loop-examples/2-setTimeout.js,1-event-loop-examples/3-setInterval.js) — setTimeout, setInterval, and the event loop - Callback Patterns (
2-async-patterns/) — Callbacks, promises, and async/await examples
- Basic HTTP Server (
1-event-loop-examples/4-server.js) — Creating a simple Node.js HTTP server - HTTP Module Fundamentals (
12-http-module.js) — Request/response handling - Streaming HTTP (
17-http-stream.js) — Efficient handling of large data transfers
- Events Module (
13-events.js) — Creating and listening to custom events - Request Events (
14-request-event.js) — Understanding event-driven architecture
- Stream Fundamentals (
16-stream.js) — Working with readable, writable, and transform streams - Efficient Large File Processing (
15-big-file.js) — How to handle large files without consuming excessive memory
node-tutorial/
├── README.md # This file
├── package.json # Project dependencies
├── app.js # Simple entry point
│
├── 1-default.js through 17-...js # Sequential tutorials (core concepts)
│
├── 1-event-loop-examples/ # Event loop demonstrations
│ ├── 1-read-file.js
│ ├── 2-setTimeout.js
│ ├── 3-setInterval.js
│ └── 4-server.js
│
├── 2-async-patterns/ # Async/await, promises, callbacks
│ └── (multiple pattern examples)
│
└── content/ # Sample data files used by examples
└── first.txt
- Node.js 14+ (16+ recommended)
- npm (comes with Node.js)
# Clone the repository
git clone https://github.com/Naveen-Kumar45/node-tutorial.git
cd node-tutorial
# Install dependencies
npm installOption 1: Run the entry point
npm start
# or
node app.jsOption 2: Run individual tutorials
Start with the fundamentals:
node 1-default.js
node 2-globals.js
node 3--modules.jsExplore file system operations:
node 10-fs-sync-module.js # Synchronous file reading
node 11-fs-async-module.js # Asynchronous file readingDive into the event loop:
node 1-event-loop-examples/1-read-file.js
node 1-event-loop-examples/2-setTimeout.js
node 1-event-loop-examples/4-server.js # Starts server on port 5000Understand async patterns:
node 2-async-patterns/callbacks.js
node 2-async-patterns/promises.js
node 2-async-patterns/async-await.jsLearn about HTTP, streams, and events:
node 12-http-module.js
node 16-stream.js
node 13-events.jsFollow this sequence to build a strong foundation in Node.js:
-
Start with Basics (5–10 min)
1-default.js— Understand what's available globally in Node2-globals.js— Explore Node's global namespace
-
Master Modules (10–15 min)
3--modules.js— Learn the CommonJS module system5-utils.js— See how to import and use utilities6-alternative.js— Alternative module patterns
-
Work with the OS & File Paths (5 min)
8-OS-module.js— Operating system information9-path-module.js— Path manipulation utilities
-
Understand the Event Loop (20–30 min) ⭐
1-event-loop-examples/1-read-file.js— Async file reading1-event-loop-examples/2-setTimeout.js— Timer mechanics1-event-loop-examples/3-setInterval.js— Recurring events
-
Learn File System Operations (15–20 min)
10-fs-sync-module.js— Blocking operations (blocking)11-fs-async-module.js— Non-blocking operations (non-blocking)- Understand the performance differences
-
Explore Async Patterns (20–30 min) ⭐
2-async-patterns/folder — Callbacks, promises, async/await- Learn the evolution of async JavaScript
-
Build an HTTP Server (15–20 min)
1-event-loop-examples/4-server.js— Simple server (run and visithttp://localhost:5000)12-http-module.js— HTTP module deep dive14-request-event.js— Event-driven request handling
-
Master Streams & Events (20–30 min) ⭐
13-events.js— Custom event emitters16-stream.js— Working with streams15-big-file.js— Efficient large file processing17-http-stream.js— Streaming HTTP responses
Understanding these fundamentals is critical for:
- ✅ Writing efficient, scalable Node.js applications — Async patterns and streams are essential for performance
- ✅ Avoiding common pitfalls — The event loop, callback hell, and blocking operations trip up many beginners
- ✅ Building production-ready servers — HTTP, events, and streams power real-world APIs
- ✅ Contributing to open-source Node projects — These concepts appear everywhere
- ✅ Interviewing for Node.js roles — These topics are frequently asked about
- Language: JavaScript (CommonJS)
- Runtime: Node.js
- Key Library: lodash (for utility examples)
- Dev Tool: nodemon (auto-restart during development)
- Pick a topic from the "Topics Covered" section above
- Open the corresponding file and read the code
- Run the file using
node filename.js - Observe the output and understand what's happening
- Modify the code to experiment and deepen your understanding
- Move to the next example when you're comfortable
- Run each example step-by-step — Don't just read, execute and observe
- Modify the code — Change values, add console.logs, experiment
- Compare examples — Notice the differences between sync and async file operations
- Understand the "why" — Each example teaches a specific lesson
- Take notes — Document what each concept does and when to use it
{
"dependencies": {
"lodash": "^4.18.1" // Utility functions for data manipulation
},
"devDependencies": {
"nodemon": "^3.1.14" // Auto-restart Node.js during development
}
}No environment variables are required to run any examples.
This is an open learning resource! If you'd like to contribute:
- Add clarifying comments to existing examples
- Create additional examples for topics not yet covered
- Improve explanations in this README
- Report confusing sections as issues
- Suggest new topics that would help learners
Please keep contributions focused and beginner-friendly!
ISC License — Feel free to use and modify these examples for learning.
- Open an issue if something doesn't work or needs clarification
- Discuss learning paths and Node.js concepts in discussions
- Suggest improvements to make this tutorial more helpful
Happy Learning! 🚀 Start with the basics and build your way up to mastering Node.js fundamentals.