This repository contains a comprehensive Node.js Express framework learning project designed to help developers master server-side JavaScript development, Express.js framework, MongoDB integration, and full-stack web application architecture. The project features a complete course management system with CRUD operations, template engine integration, database modeling, and modern web development practices. It serves as a complete learning platform for understanding Node.js and Express.js development from basics to advanced concepts.
- Node.js (version 14 or higher) and npm installed on your system
- MongoDB installed and running locally (or MongoDB Atlas account)
- A modern web browser (Chrome, Firefox, Edge, Safari, etc.)
- (Optional) A code editor like VS Code, Sublime Text, or Atom for easier code navigation
- Basic understanding of JavaScript, HTML, CSS, and web development concepts
-
Clone the repository (if not already downloaded):
git clone <repository-url> cd Nodejs-main
-
Install dependencies:
npm install
-
Set up MongoDB:
- Install MongoDB locally or use MongoDB Atlas
- Ensure MongoDB is running on
mongodb://localhost:27017/
- The application will automatically create the
education_dev
database
-
Start the application:
npm start
This will start the server with nodemon for automatic reloading at http://localhost:3000.
-
Watch SCSS files (in a separate terminal):
npm run watch
This will automatically compile SCSS files to CSS when changes are detected.
-
Build the application:
npm run build
-
Start production server:
node src/index.js
Note: The application uses nodemon for development, which automatically restarts the server when you make changes to the source code. The SCSS watcher will automatically compile your stylesheets.
Nodejs-main/
├── src/
│ ├── app/
│ │ ├── controllers/
│ │ │ ├── CourseController.js
│ │ │ ├── MeController.js
│ │ │ ├── NewsController.js
│ │ │ └── SiteController.js
│ │ └── models/
│ │ └── Course.js
│ ├── config/
│ │ └── db/
│ │ └── index.js
│ ├── public/
│ │ ├── css/
│ │ │ ├── app.css
│ │ │ └── app.css.map
│ │ └── img/
│ │ └── logo.png
│ ├── resources/
│ │ ├── scss/
│ │ │ ├── _variables.scss
│ │ │ └── app.scss
│ │ └── views/
│ │ ├── courses/
│ │ │ ├── create.hbs
│ │ │ ├── edit.hbs
│ │ │ └── show.hbs
│ │ ├── home.hbs
│ │ ├── layouts/
│ │ │ └── main.hbs
│ │ ├── me/
│ │ │ └── stored-courses.hbs
│ │ ├── news.hbs
│ │ ├── partials/
│ │ │ ├── footer.hbs
│ │ │ └── header.hbs
│ │ └── search.hbs
│ ├── routes/
│ │ ├── course.js
│ │ ├── index.js
│ │ ├── me.js
│ │ ├── news.js
│ │ └── site.js
│ ├── util/
│ │ └── mongoose.js
│ └── index.js
├── nodemon.json
├── package-lock.json
├── package.json
└── README.md
- src/app/controllers/: MVC controllers handling business logic
CourseController.js
: Course CRUD operations and managementMeController.js
: User-specific course managementNewsController.js
: News content handlingSiteController.js
: Main site pages and search functionality
- src/app/models/: Database models using Mongoose ODM
Course.js
: Course data model with slug generation and validation
- src/config/db/: Database configuration
index.js
: MongoDB connection setup and management
- src/public/: Static assets served directly to the browser
css/
: Compiled CSS files and source mapsimg/
: Image assets and logos
- src/resources/: Application resources and templates
scss/
: SCSS source files for stylingviews/
: Handlebars template files organized by feature
- src/routes/: Express.js route definitions
course.js
: Course-related routes (CRUD operations)me.js
: User-specific routesnews.js
: News content routessite.js
: Main site routes (home, search)index.js
: Route initialization and organization
- src/util/: Utility functions and helpers
mongoose.js
: Mongoose helper functions for data transformation
- src/index.js: Application entry point and server configuration
- Express.js Framework: Modern Node.js web application framework
- MVC Architecture: Model-View-Controller pattern implementation
- MongoDB Integration: NoSQL database with Mongoose ODM
- Template Engine: Handlebars for server-side rendering
- CRUD Operations: Complete Create, Read, Update, Delete functionality
- RESTful API Design: Proper HTTP method usage and route structure
- Static File Serving: CSS, images, and other static assets
- Form Handling: POST/PUT/DELETE request processing
- URL Slug Generation: SEO-friendly URLs for courses
- SCSS Compilation: Modern CSS preprocessing with automatic compilation
- Development Tools: Nodemon for automatic server restart
- Method Override: Support for PUT/DELETE requests in forms
- Morgan Logging: HTTP request logging (configurable)
- Bootstrap Integration: Modern responsive UI framework
- YouTube Integration: Automatic thumbnail generation from video IDs
This module covers the fundamentals of Express.js:
- Server Setup: Creating and configuring Express applications
- Middleware Integration: Body parsing, static files, method override
- Template Engine Configuration: Handlebars setup and customization
- Route Organization: Modular routing with Express Router
- Database Connection: MongoDB integration with Mongoose
- Development Tools: Nodemon configuration for hot reloading
This module demonstrates Model-View-Controller pattern:
- Course Model: Mongoose schema with validation and middleware
- Slug Generation: Automatic URL-friendly slug creation
- Timestamps: Automatic creation and update timestamps
- Data Validation: Required fields and data type validation
- Layout System: Master layout with partials (header, footer)
- Template Organization: Feature-based view organization
- Bootstrap Integration: Responsive UI components
- Dynamic Content: Server-side rendering with Handlebars
- Form Templates: Create, edit, and search forms
- CRUD Operations: Complete course management functionality
- Request Handling: GET, POST, PUT, DELETE method processing
- Data Transformation: Mongoose object to plain object conversion
- Error Handling: Proper error catching and next() usage
- Redirect Management: Proper HTTP redirects after operations
This module covers Express.js routing:
- Modular Routes: Separate route files for different features
- Route Parameters: Dynamic URL parameters and slug handling
- HTTP Methods: Proper usage of GET, POST, PUT, DELETE
- Route Organization: Clean separation of concerns
- Middleware Integration: Route-specific middleware usage
This module covers MongoDB and Mongoose:
- Connection Management: MongoDB connection setup and error handling
- Schema Design: Mongoose schema definition and validation
- Middleware: Pre-save hooks for data transformation
- Query Operations: Find, create, update, delete operations
- Data Relationships: Model associations and references
This module covers client-side development:
- SCSS Processing: Modern CSS with variables and nesting
- Bootstrap Framework: Responsive design and UI components
- Static Asset Management: CSS, images, and other resources
- Template Integration: Server-side rendering with dynamic content
- Form Handling: Client-side form validation and submission
- Node.js: JavaScript runtime for server-side development
- Express.js 5.1.0: Web application framework
- MongoDB: NoSQL database for data storage
- Mongoose 7.8.7: MongoDB object modeling tool
- Express-Handlebars 8.0.1: Template engine for server-side rendering
- Method-Override 3.0.0: HTTP method override middleware
- Morgan 1.10.0: HTTP request logger middleware
- Nodemon 3.1.10: Development server with auto-restart
- Sass 1.89.0: CSS preprocessor for advanced styling
- Bootstrap 5.3.6: Frontend CSS framework
- Slugify 1.6.6: URL-friendly string generation
- Start Development Server: Run
npm start
for hot reloading - Watch SCSS Files: Run
npm run watch
for automatic CSS compilation - Database Setup: Ensure MongoDB is running locally
- Code Changes: Files automatically reload when modified
- Build Assets: Compile SCSS and optimize static files
- Environment Setup: Configure production database and environment variables
- Server Deployment: Deploy to production server or cloud platform
- Monitoring: Set up logging and monitoring for production
- Start with
src/index.js
to understand Express.js setup - Explore
src/routes/
to learn routing concepts - Study
src/app/models/
for database modeling
- Implement CRUD operations in controllers
- Create custom routes and middleware
- Design and implement new features
- Add authentication and authorization
- Implement API endpoints
- Add testing and deployment configurations
- Optimize performance and security
- MVC Pattern: Clear separation of concerns
- Modular Architecture: Feature-based file organization
- Error Handling: Proper error catching and logging
- Security: Input validation and sanitization
- Performance: Efficient database queries and caching
- Code Organization: Consistent naming conventions and structure
- Documentation: Clear code comments and README
- Version Control: Proper Git workflow and commit messages
GET /courses
- List all coursesGET /courses/create
- Show course creation formPOST /courses/store
- Create new courseGET /courses/:slug
- Show course detailsGET /courses/:id/edit
- Show course edit formPUT /courses/:id
- Update courseDELETE /courses/:id
- Delete course
GET /me/stored/courses
- Show user's stored coursesGET /me/trash/courses
- Show deleted coursesPATCH /me/stored/courses/:id/restore
- Restore deleted courseDELETE /me/stored/courses/:id/force
- Permanently delete course
GET /
- Home pageGET /search
- Search pagePOST /search
- Search functionalityGET /news
- News page
- Database Connection: Ensure MongoDB is running on localhost:27017
- Port Conflicts: Change port in
src/index.js
if 3000 is busy - Dependencies: Run
npm install
if modules are missing - SCSS Compilation: Ensure
npm run watch
is running for CSS updates - File Permissions: Check file permissions for static assets
- Console Errors: Check terminal and browser console for error messages
This is a learning project designed for educational purposes. Feel free to:
- Modify examples to experiment with different approaches
- Add new features and functionality
- Improve documentation and comments
- Share your learning experiences
- Report bugs and suggest improvements
- Express.js Documentation
- MongoDB Documentation
- Mongoose Documentation
- Handlebars Documentation
- Node.js Documentation
- Bootstrap Documentation
- Sass Documentation
For questions or contributions, please open an issue or pull request on the GitHub repository.
This project is licensed under the ISC License - see the LICENSE file for details.