Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Fundamentals Tutorial

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.


📚 What This Repository Is

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.


🎯 Topics Covered

1. Core Node.js Basics

  • 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

2. File System (fs) Operations

  • 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

3. Event Loop & Asynchronous JavaScript

  • 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

4. HTTP & Server Development

  • 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

5. Events & Event Emitters

  • Events Module (13-events.js) — Creating and listening to custom events
  • Request Events (14-request-event.js) — Understanding event-driven architecture

6. Streams & Large File Handling

  • 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

📂 Repository Structure

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

🚀 Getting Started

Prerequisites

  • Node.js 14+ (16+ recommended)
  • npm (comes with Node.js)

Installation

# Clone the repository
git clone https://github.com/Naveen-Kumar45/node-tutorial.git
cd node-tutorial

# Install dependencies
npm install

Running Examples

Option 1: Run the entry point

npm start
# or
node app.js

Option 2: Run individual tutorials

Start with the fundamentals:

node 1-default.js
node 2-globals.js
node 3--modules.js

Explore file system operations:

node 10-fs-sync-module.js    # Synchronous file reading
node 11-fs-async-module.js   # Asynchronous file reading

Dive 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 5000

Understand async patterns:

node 2-async-patterns/callbacks.js
node 2-async-patterns/promises.js
node 2-async-patterns/async-await.js

Learn about HTTP, streams, and events:

node 12-http-module.js
node 16-stream.js
node 13-events.js

📖 Recommended Learning Path

Follow this sequence to build a strong foundation in Node.js:

  1. Start with Basics (5–10 min)

    • 1-default.js — Understand what's available globally in Node
    • 2-globals.js — Explore Node's global namespace
  2. Master Modules (10–15 min)

    • 3--modules.js — Learn the CommonJS module system
    • 5-utils.js — See how to import and use utilities
    • 6-alternative.js — Alternative module patterns
  3. Work with the OS & File Paths (5 min)

    • 8-OS-module.js — Operating system information
    • 9-path-module.js — Path manipulation utilities
  4. Understand the Event Loop (20–30 min) ⭐

    • 1-event-loop-examples/1-read-file.js — Async file reading
    • 1-event-loop-examples/2-setTimeout.js — Timer mechanics
    • 1-event-loop-examples/3-setInterval.js — Recurring events
  5. 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
  6. Explore Async Patterns (20–30 min) ⭐

    • 2-async-patterns/ folder — Callbacks, promises, async/await
    • Learn the evolution of async JavaScript
  7. Build an HTTP Server (15–20 min)

    • 1-event-loop-examples/4-server.js — Simple server (run and visit http://localhost:5000)
    • 12-http-module.js — HTTP module deep dive
    • 14-request-event.js — Event-driven request handling
  8. Master Streams & Events (20–30 min) ⭐

    • 13-events.js — Custom event emitters
    • 16-stream.js — Working with streams
    • 15-big-file.js — Efficient large file processing
    • 17-http-stream.js — Streaming HTTP responses

💡 Why This Tutorial Matters

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

🔧 Tech Stack

  • Language: JavaScript (CommonJS)
  • Runtime: Node.js
  • Key Library: lodash (for utility examples)
  • Dev Tool: nodemon (auto-restart during development)

📝 How to Use This Repository

  1. Pick a topic from the "Topics Covered" section above
  2. Open the corresponding file and read the code
  3. Run the file using node filename.js
  4. Observe the output and understand what's happening
  5. Modify the code to experiment and deepen your understanding
  6. Move to the next example when you're comfortable

🎓 Best Practices for Learning

  • 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

{
  "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.


💬 Contributing

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!


📄 License

ISC License — Feel free to use and modify these examples for learning.


🤝 Questions or Issues?

  • 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.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages