Skip to content

Repository files navigation

Node.js Built-in Modules Exercises

A comprehensive collection of Node.js exercises demonstrating the use of built-in modules, specifically readline and fs modules with modern promise-based APIs.

📚 Projects Overview

Readline Module Exercises

1. node-readline-1 - Personalized Greeting

  • Files: index.js (CommonJS), index.mjs (ES6 modules)
  • Features: Interactive name input with personalized greeting
  • Technologies: readline, process

2. node-readline-2 - Interactive Input Examples

  • Files: index.js, index-async.js
  • Features: Basic readline usage and async patterns
  • Technologies: readline, process

3. node-readline-3 - Password Validation

  • Files: index.js (CommonJS), index.mjs (ES6 modules)
  • Features: Password validation with criteria checking
  • Technologies: readline, process
  • Validation: Minimum length, uppercase, lowercase letters

4. node-readline-4 - Number Guessing Game

  • Files: index.mjs
  • Features: Interactive number guessing with retry mechanism
  • Technologies: readline/promises, process
  • Game Logic: Random number generation, attempt tracking, input validation

5. node-readline-5 - User Information Collection

  • Files: index.mjs
  • Features: Multi-field form with comprehensive validation
  • Technologies: readline/promises, process
  • Validation: Name, age, email validation with retry mechanism

File System Module Exercises

1. node-fs-1 - File Operations

  • Files: index.js, create.js, sample.txt, output.txt
  • Features: File reading and writing operations
  • Technologies: fs, path
  • Operations: readFile(), writeFile()

2. node-fs-3 - Directory Listing

  • Files: index.mjs
  • Features: Directory contents listing with error handling
  • Technologies: fs/promises, path
  • Operations: readdir() with async/await

3. node-fs-4 - Interactive File Reader

  • Files: index.mjs
  • Features: Interactive file reading with user input
  • Technologies: readline/promises, fs/promises
  • Features: User-friendly interface, error handling

4. node-fs-5 - Digital Diary Application

  • Files: index.mjs, diary.txt
  • Features: Complete diary application with timestamps
  • Technologies: readline/promises, fs/promises
  • Features: Read/Write entries, automatic timestamps, input validation

🚀 Key Features Demonstrated

Modern JavaScript Patterns

  • ✅ ES6 Modules with import/export
  • ✅ Async/Await syntax for clean asynchronous code
  • ✅ Promise-based APIs (fs/promises, readline/promises)
  • ✅ Error Handling with try/catch blocks

Node.js Built-in Modules

  • ✅ Readline Module: Interactive command-line interfaces
  • ✅ File System Module: File and directory operations
  • ✅ Process Module: Standard input/output handling
  • ✅ Path Module: Cross-platform file path handling

Best Practices

  • ✅ Input Validation: Comprehensive user input checking
  • ✅ Error Handling: Graceful error management
  • ✅ User Experience: Clear prompts and feedback
  • ✅ Code Organization: Modular function design
  • ✅ Resource Management: Proper cleanup of interfaces

🛠️ Technologies Used

  • Node.js - Runtime environment
  • JavaScript ES6+ - Modern JavaScript features
  • CommonJS - Traditional Node.js module system
  • ES6 Modules - Modern module system
  • Promises - Asynchronous programming
  • Async/Await - Clean asynchronous syntax

📁 Project Structure

act-node-built-in-modules/
├── node-readline-1/          # Personalized greeting
├── node-readline-2/          # Interactive input examples
├── node-readline-3/          # Password validation
├── node-readline-4/          # Number guessing game
├── node-readline-5/          # User information collection
├── node-fs-1/               # File operations
├── node-fs-3/               # Directory listing
├── node-fs-4/               # Interactive file reader
├── node-fs-5/               # Digital diary application
└── README.md                # This file

🎯 Learning Outcomes

After completing these exercises, you will understand:

  1. Readline Module: How to create interactive command-line applications
  2. File System Module: How to read, write, and manage files and directories
  3. Promise-based APIs: Modern asynchronous programming patterns
  4. Error Handling: Robust error management in Node.js applications
  5. Input Validation: Ensuring data integrity in user applications
  6. Module Systems: Both CommonJS and ES6 module patterns

🏃‍♂️ Running the Projects

Each project can be run independently:

# Navigate to any project folder
cd node-readline-1

# Run CommonJS version
node index.js

# Run ES6 modules version (if available)
node index.mjs

# Or use npm scripts
npm start

📝 Notes

  • All projects include comprehensive error handling
  • Input validation is implemented where appropriate
  • Both CommonJS and ES6 module patterns are demonstrated
  • Modern promise-based APIs are used throughout
  • User-friendly interfaces with clear feedback

🤝 Contributing

This is a learning project demonstrating Node.js built-in modules. Feel free to explore the code and experiment with modifications!


Created as part of Node.js learning journey 🚀

About

Node.js built-in modules exercises - readline and fs modules with promises

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages