This is a backend-focused web application built with Express.js as part of the Agmo x MyMahir Full Stack Training (Week 1). It demonstrates the fundamentals of building a RESTful API and a Server-Side Rendered (SSR) web application using Node.js.
The project covers essential concepts including routing, middleware, database connectivity (MySQL), template rendering (EJS), and authentication flows.
- Web Server: Built with Express.js to handle HTTP requests.
- MVC Architecture: implementation of Models, Views, and Controllers (via Routes).
- Template Engine: Dynamic HTML rendering using EJS.
- RESTful API:
- Student API: CRUD operations for managing students.
- Auth API: Authentication endpoints (Register/Login) using JWT & bcrypt.
- Database Integration: Asynchronous MySQL connection using
mysql2. - Middleware:
- CORS: Cross-Origin Resource Sharing configuration.
- Method Override: Support for PUT/DELETE methods in HTML forms.
- Body Parsing: JSON and URL-encoded data handling.
- Demonstration Routes: Examples of GET, POST, PUT, DELETE, Query Params, and URL Params.
- Runtime: Node.js
- Framework: Express.js
- Database: MySQL
- Templating: EJS
- Authentication:
jsonwebtoken,bcrypt - Utilities:
dotenv(Environment Variables),nodemon(Dev Server)
├── public/ # Static files (HTML, CSS, Images)
├── routes/ # Application routes
│ ├── api/ # API endpoints (Auth, Students)
│ ├── contact/ # Contact feature routes
│ ├── student/ # Student UI routes
│ └── blogRoutes.js # Blog post routes
├── views/ # EJS Templates
├── database.js # Database connection configuration
├── server.js # Main application entry point
├── package.json # Project dependencies and scripts
└── .env # Environment variables (not committed)-
Clone the repository:
git clone <repository-url> cd <project-folder>
-
Install dependencies:
npm install
-
Configure Environment Variables: Create a
.envfile in the root directory and add your MySQL configuration:PORT=3000 DB_HOST=localhost DB_USER=root DB_PASSWORD=your_password DB_NAME=mymahirdb DB_PORT=3306 JWT_SECRET=your_jwt_secret_key
(Note: Ensure you have a MySQL database created similar to
mymahirdb) -
Database Setup:
- Ensure your MySQL server is running.
- Create the necessary tables (Students, Users, etc.) expected by the application in your database.
Development Mode (with auto-reload):
npm run devProduction Start:
npm startAccess the application at: http://localhost:3000
- Home:
GET / - Students (UI):
GET /students - Blog (UI):
GET /posting - API - Students:
GET /api/students - API - Auth:
POST /api/auth/login,POST /api/auth/register
This project is for educational purposes as part of the Agmo x MyMahir training program.
