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!