A comprehensive learning repository for Node.js fundamentals and best practices.
This repository contains learning materials and code examples for Node.js development. Each module builds upon the previous one, providing a structured learning path from basics to more advanced concepts.
Directory: 01-Introduction-to-Node.js
Learn the fundamentals of Node.js, including:
- What is Node.js and how it works
- JavaScript on the server
- When and why to use Node.js
- Key features and advantages
- Popular use cases
Files:
Introduction-to-Node.js.md- Comprehensive documentation
Key Topics:
- Node.js runtime environment
- V8 JavaScript Engine
- Single-threaded, event-driven architecture
- NPM ecosystem
- Use cases and best practices
Directory: 02-Reading-and-Writing-Files
Learn how to interact with the file system in Node.js:
- Synchronous vs Asynchronous file operations
- Reading files with
fs.readFileSync()andfs.readFile() - Writing files with
fs.writeFileSync()andfs.writeFile() - Understanding blocking vs non-blocking I/O
Files:
sync-way.js- Synchronous file operations exampleasync-way.js- Asynchronous file operations exampleinput.txt- Sample input fileReading-and-Writing-Files.md- Complete documentation
Key Topics:
- File System (
fs) module - Synchronous operations (blocking)
- Asynchronous operations (non-blocking)
- Callbacks and error handling
- When to use each approach
Directory: 03-Creating-web-server
Build your first HTTP server using Node.js:
- Creating HTTP servers with the
httpmodule - Handling different routes
- Request and response objects
- Setting status codes and headers
- Building a simple web server
Files:
App.js- HTTP server with routingCreating-web-server.md- Complete documentation
Key Topics:
- HTTP module
createServer()method- Request (
req) and Response (res) objects - Route handling
- Status codes and headers
res.writeHead()andres.end()
Directory: 04-Building-simple-api
Create a simple REST API that serves JSON data:
- Building API endpoints
- Serving JSON data from files
- Loading data at server startup
- Understanding
__dirname - Setting proper Content-Type headers
Files:
App.js- Simple API serverdata.json- Sample JSON dataBuilding-simple-api.md- Complete documentation
Key Topics:
- REST API concepts
- JSON data handling
- File system integration
- API endpoints
- Content-Type headers
- Synchronous vs Asynchronous data loading
Directory: 05-Parsing-variables-from-url
Learn how to extract data from URLs:
- Parsing query strings
- Extracting URL parameters
- Using modern WHATWG URL API
- Working with URLSearchParams
- Combining URL parameters and query strings
Files:
App.js- Server with URL parsing examplesParsing-variables-from-url.md- Complete documentation
Key Topics:
- Modern URL API (WHATWG standard)
- Query string parameters
- URL path parameters
- URLSearchParams object
new URL()constructor- Extracting dynamic route segments
Directory: 06-Introduction-to-NPM
Master Node Package Manager:
- Understanding npm and package management
- Creating and managing
package.json - Installing and managing dependencies
- NPM scripts
- Best practices and workflows
Files:
App.js- Example server using npmpackage.json- Project configuration.gitignore- Git ignore fileIntroduction-to-NPM.md- Complete documentation
Key Topics:
- Package management
package.jsonstructure- Dependencies vs DevDependencies
- NPM commands
- NPM scripts
node_modulesandpackage-lock.json- Version ranges and semantic versioning
nodejs-learning/
├── 01-introduction-tonNode.js/
│ └── introduction-to-node.js.md
├── 02-reading-and-writing-files/
│ ├── sync-way.js
│ ├── async-way.js
│ ├── input.txt
│ ├── sync-output.txt
│ ├── async-output.txt
│ └── reading-and-writing-files.md
├── 03-creating-web-server/
│ ├── App.js
│ └── creating-web-server.md
├── 04-building-simple-api/
│ ├── App.js
│ ├── data.json
│ └── building-simple-api.md
├── 05-parsing-variables-from-url/
│ ├── App.js
│ └── parsing-variables-from-url.md
├── 06-introduction-to-npm/
│ ├── App.js
│ ├── package.json
│ ├── package-lock.json
│ ├── .gitignore
│ └── introduction-to-npm.md
└── README.md
- Node.js installed (v12 or higher recommended)
- Basic knowledge of JavaScript
- A code editor (VS Code recommended)
- Terminal/Command Prompt
- Clone this repository (or download the files)
- Ensure Node.js is installed:
node --version npm --version
Follow the modules in order:
- Start Here: Introduction to Node.js
- File Operations: Reading and Writing Files
- Web Servers: Creating Web Server
- APIs: Building Simple API
- URL Parsing: Parsing Variables from URL
- Package Management: Introduction to NPM
Each module contains working code examples. To run them:
# Navigate to the module directory
cd 03-Creating-web-server
# Run the example
node App.jsFor modules with npm dependencies (like module 06):
cd 06-Introduction-to-NPM
# Install dependencies first
npm install
# Run the server
npm start
# Or run in development mode
npm run dev- ✅ Node.js runtime and V8 engine
- ✅ Event-driven, non-blocking I/O
- ✅ Single-threaded architecture
- ✅ File system operations
- ✅ HTTP servers and APIs
- ✅ Synchronous vs Asynchronous operations
- ✅ Reading and writing files
- ✅ Error handling
- ✅ Best practices
- ✅ Creating HTTP servers
- ✅ Handling routes
- ✅ Request and response objects
- ✅ Building REST APIs
- ✅ Serving JSON data
- ✅ Modern URL API (WHATWG)
- ✅ Query string parsing
- ✅ URL parameter extraction
- ✅ URLSearchParams
- ✅ NPM basics
- ✅ package.json
- ✅ Dependencies management
- ✅ NPM scripts
- ✅ Best practices
- Always use asynchronous methods for production applications
- Handle errors properly in all file and network operations
- Use modern APIs (avoid deprecated methods like
url.parse()) - Set appropriate Content-Type headers for API responses
- Keep dependencies updated and use semantic versioning
- Commit package-lock.json but not
node_modules - Use npm scripts for common tasks
This repository covers:
- Module 1: Understanding Node.js fundamentals
- Module 2: File system operations (sync vs async)
- Module 3: Creating HTTP web servers
- Module 4: Building simple REST APIs
- Module 5: Parsing URL parameters and query strings
- Module 6: NPM package management
Each module builds upon the previous knowledge, creating a comprehensive learning path for Node.js development.
Happy Learning! 🚀
This repository is part of a Node.js learning journey. Keep coding and exploring!