Skip to content

Latest commit

 

History

History
371 lines (289 loc) · 13.5 KB

File metadata and controls

371 lines (289 loc) · 13.5 KB

Node.js Complete E-Commerce Application

Status: Course Completed | A comprehensive full-stack Node.js project built from the ground up

This project represents the complete journey through modern Node.js backend development, from fundamental concepts to production-ready features. Built as a fully functional e-commerce platform with authentication, payments, file handling, and real-time features.


Course Completion Summary

This project was developed as part of a comprehensive Node.js course, taking me from beginner to confident full-stack developer. Every line of code represents hands-on learning, debugging sessions, and real-world problem-solving.

What I've Learned

Core Node.js & Backend Fundamentals

  • Express.js server configuration and middleware architecture
  • MVC (Model-View-Controller) design pattern implementation
  • RESTful API design and routing best practices
  • Asynchronous JavaScript (Promises, async/await)
  • Error handling and debugging strategies
  • Environment variable management with dotenv

Database Management

  • SQL (MySQL): Raw queries, joins, transactions, Sequelize ORM
  • NoSQL (MongoDB): Document-based storage, MongoDB Atlas cloud deployment
  • Mongoose ODM: Schema design, validation, relationships, population
  • Database migration strategies and data integrity

Authentication & Security

  • Session-based authentication with express-session
  • Password hashing with bcryptjs
  • CSRF protection with csurf
  • Authorization and route protection middleware
  • Cookie management and security best practices
  • Password reset functionality with crypto tokens

Advanced Features

  • File Upload/Download: Multer integration, file validation, storage management
  • PDF Generation: Dynamic invoice creation with PDFKit
  • Email Integration: Nodemailer with SendGrid/Mailtrap
  • Payment Processing: Stripe integration for checkout sessions
  • Input Validation: express-validator for server-side validation
  • Pagination: Efficient data loading with skip/limit queries
  • Async Requests: Client-side JavaScript with Fetch API for dynamic updates

Frontend & Templating

  • EJS templating engine with partials and includes
  • Dynamic content rendering and data binding
  • Client-side JavaScript for interactive features
  • Form validation and error display patterns
  • Responsive design with CSS

Technologies & Tools Used

Backend Stack

  • Node.js (v22.x) - JavaScript runtime
  • Express.js - Web framework
  • MongoDB - NoSQL database
  • Mongoose - MongoDB ODM
  • MySQL - Relational database
  • Sequelize - SQL ORM

Authentication & Security

  • express-session - Session management
  • connect-mongodb-session - MongoDB session store
  • bcryptjs - Password hashing
  • csurf - CSRF protection
  • connect-flash - Flash messages

File & Data Processing

  • Multer - File upload handling
  • PDFKit - PDF document generation
  • Nodemailer - Email sending
  • express-validator - Input validation

Payment Integration

  • Stripe - Payment processing

Frontend

  • EJS - Templating engine
  • CSS3 - Styling
  • Vanilla JavaScript - Client-side interactivity

Development Tools

  • Git & GitHub - Version control
  • Nodemon - Auto-restart development server
  • dotenv - Environment configuration
  • Windows PowerShell - Terminal

Complete Feature Set

User Management

✅ User registration with email validation
✅ Secure login/logout with sessions
✅ Password reset via email tokens
✅ User authorization and route protection

Product Management

✅ CRUD operations for products (Admin only)
✅ Image upload with file validation
✅ Product editing with image replacement
✅ Product deletion with file cleanup
✅ Pagination for product listings

Shopping Experience

✅ Shopping cart with add/remove/update
✅ Cart persistence across sessions
✅ Checkout process
✅ Stripe payment integration
✅ Order creation and history

Advanced Features

✅ Dynamic PDF invoice generation
✅ Secure file download with authorization
✅ Email notifications (signup, password reset)
✅ Async JavaScript for delete operations
✅ Error handling with custom error pages
✅ Flash messages for user feedback


Challenges Overcome

1. Windows-Specific Issues

  • MongoDB Package Conflicts: Windows Defender flagged update.js causing installation failures. Solution: Added folder exclusions and downgraded to compatible version.
  • File Path Handling: Windows backslash vs Unix forward slash issues in file paths. Solution: Used path.join() for cross-platform compatibility.
  • Filename Validation: toISOString() colons invalid in Windows filenames. Solution: Replaced colons with hyphens using regex.

2. Mongoose Version Updates

  • Deprecated .execPopulate(): Upgraded from Mongoose 5.x to 6.x patterns where .populate() returns promises directly.
  • Schema Validation: Implemented proper error handling for missing required fields.

3. Authentication Flow

  • Session vs Request Data: Understanding when to use req.session.user vs req.user and proper middleware ordering.
  • Password Reset Logic: Implementing secure token generation, expiration, and validation flow.

4. Email Integration

  • SendGrid Setup: Navigated sender verification requirements and API key management.
  • Error Handling: Made email sending non-blocking to prevent app crashes during development.

5. Stripe Payment Integration

  • API Updates: Adapted to Stripe's newer checkout session structure with price_data instead of deprecated SKU patterns.
  • Environment Variables: Properly accessing process.env values (not string literals!).

6. File Upload & Management

  • Multer Configuration: Proper storage configuration with unique filenames.
  • File Cleanup: Implementing helper functions to delete old images when products are updated/deleted.
  • Authorization: Ensuring users can only download invoices for their own orders.

7. Validation & Error Handling

  • DRY Principle: Refactored duplicate error rendering code into reusable helper functions.
  • express-validator Compatibility: Handled e.param vs e.path differences across versions.
  • Defensive Programming: Added checks for undefined session states in error handlers.

Real-World Relevance

Industry-Standard Patterns

This project implements patterns and practices used in production applications:

  • Separation of Concerns: MVC architecture keeps code organized and maintainable
  • Security First: CSRF protection, password hashing, and authorization checks
  • Scalable Architecture: Modular structure ready for team collaboration
  • Error Handling: Proper error pages and logging for debugging

Production-Ready Skills

  • Database Design: Normalized SQL and denormalized NoSQL approaches
  • Payment Processing: Real payment gateway integration (Stripe)
  • File Management: Secure upload, storage, and retrieval
  • Email Services: Transactional email patterns
  • Session Management: Stateful authentication at scale

Modern Development Workflow

  • Version Control: Git branching strategy with feature branches
  • Environment Configuration: Proper secrets management
  • Debugging: Systematic troubleshooting and console logging
  • Documentation: Clear code comments and commit messages

Future Potential & Next Steps

Immediate Enhancements

  • Add REST API endpoints for mobile app integration
  • Implement product search and filtering
  • Add user reviews and ratings
  • Implement admin dashboard with analytics
  • Add product categories and tags

Advanced Features

  • WebSockets: Real-time notifications for order updates
  • GraphQL API: Flexible data querying for clients
  • Microservices: Split into separate services (auth, products, orders)
  • Redis Caching: Improve performance with caching layer
  • Elasticsearch: Full-text search capabilities

Modern Stack Migration

  • TypeScript: Add type safety and better IDE support
  • Next.js: Server-side rendering and improved SEO
  • Docker: Containerization for easier deployment
  • Kubernetes: Orchestration for scaling
  • CI/CD Pipeline: Automated testing and deployment

Testing & Quality

  • Unit tests with Jest
  • Integration tests with Supertest
  • E2E tests with Cypress
  • Code coverage reporting
  • Performance monitoring with PM2

Deployment

  • Deploy to AWS EC2 / Azure / Google Cloud
  • Set up MongoDB Atlas production cluster
  • Configure Nginx reverse proxy
  • Implement SSL/TLS with Let's Encrypt
  • Set up monitoring and logging (CloudWatch, Datadog)

Project Structure

NodeJS-Project/
├── controllers/       → Business logic (admin, auth, shop, error)
├── models/           → Data models (User, Product, Order)
├── routes/           → Route definitions (admin, auth, shop)
├── views/            → EJS templates (layouts, partials)
│   ├── admin/        → Product management views
│   ├── auth/         → Login, signup, password reset
│   ├── shop/         → Store, cart, checkout, orders
│   └── includes/     → Reusable partials (header, nav, footer)
├── public/           → Static assets (CSS, JS, images)
├── data/             → File storage (invoices, uploads)
├── images/           → Product images
├── middleware/       → Custom middleware (auth, error handling)
├── util/             → Helper functions (file operations, paths)
├── .env              → Environment variables (secrets)
├── app.js            → Express app configuration
└── package.json      → Dependencies and scripts

Setup & Installation

Prerequisites

  • Node.js v22.x or higher
  • MongoDB Atlas account or local MongoDB
  • Stripe account (for payment testing)

Installation

  1. Clone the repository
git clone https://github.com/martialchess/NodeJS-Beginner-Project.git
cd NodeJS-Beginner-Project
  1. Install dependencies
npm install
  1. Configure environment variables

Create a .env file in the root directory:

PORT=3000
MONGODB_URI=your_mongodb_atlas_connection_string
SENDGRID_API_KEY=your_sendgrid_api_key
STRIPE_SECRET_KEY=your_stripe_secret_key
  1. Run the application
npm start
  1. Access the application
http://localhost:3000

Key Takeaways

Technical Skills Gained

✅ Full-stack development with Node.js and Express
✅ Database design and management (SQL & NoSQL)
✅ Authentication and authorization implementation
✅ Payment gateway integration
✅ File upload and processing
✅ Email service integration
✅ RESTful API design
✅ Error handling and debugging

Soft Skills Developed

✅ Problem-solving and debugging methodology
✅ Reading documentation and adapting to API changes
✅ Git workflow and version control best practices
✅ Code organization and maintainability
✅ Security-first mindset
✅ Persistence through complex challenges

Real-World Experience

✅ Working with external APIs and SDKs
✅ Handling platform-specific issues (Windows)
✅ Managing environment configurations
✅ Implementing production-ready features
✅ Debugging across multiple layers (frontend, backend, database)


Course Journey

This project evolved through multiple modules, each building on the previous:

  1. Basics → Understanding Node.js, npm, and Express
  2. Routing → Dynamic routes and route parameters
  3. Templating → EJS views and data rendering
  4. MVC → Architecture and code organization
  5. SQL → MySQL with raw queries and Sequelize
  6. NoSQL → MongoDB with native driver and Mongoose
  7. Sessions → User session management
  8. Authentication → Login, signup, and security
  9. Email → Nodemailer integration
  10. Advanced Auth → Password reset and tokens
  11. Validation → Input validation and error handling
  12. Error Handling → Custom error pages and logging
  13. File Upload → Multer and file storage
  14. Pagination → Efficient data loading
  15. Async Requests → Client-side JavaScript
  16. Payments → Stripe integration
  17. PDF Generation → Dynamic document creation

� Acknowledgments

This project was built following a comprehensive Node.js course, with extensive debugging, problem-solving, and feature implementation done independently. Every error was a learning opportunity, and every challenge overcome added to my development skills.

Special thanks to:

  • The course instructor for comprehensive curriculum
  • GitHub Copilot for debugging assistance and best practice recommendations
  • Stack Overflow community for specific issue solutions
  • Open-source maintainers of all the packages used

� License

This project is for educational purposes and personal portfolio demonstration.


� Connect

GitHub: martialchess
Repository: NodeJS-Beginner-Project


Built with ❤️ and lots of debugging sessions 🐛➡️✨

Special Thanks to Maximillian Schwarzmuller for the Udemy Course that made this project possible.