A robust backend API for managing online courses, handling both admin and user operations. Built with Express.js and MongoDB, this API provides secure authentication and comprehensive course management features.
-
Authentication
- Secure signup with email validation
- JWT-based signin system
- Protected routes with admin authentication
-
Course Management
- Create new courses with detailed information
- Update existing course details
- View all courses created by the admin
- Input validation for course data
-
Authentication
- User signup with email validation
- Secure signin with JWT tokens
- Protected user routes
-
Course Access
- Browse available courses
- Purchase courses
- View purchased courses
- Track course enrollment history
- Node.js
- Express.js
- MongoDB (with Mongoose)
- bcrypt for password hashing
- JWT for authentication
- Zod for input validation
POST /admin/signup
POST /admin/signin
POST /admin/course
PUT /admin/course
GET /admin/course/bulk
POST /user/signup
POST /user/signin
GET /user/purchases
POST /course/purchase
GET /course/preview
-
Clone the repository:
git clone https://github.com/govindup63/coursera-backend.git
-
Install dependencies:
cd coursera-backend npm install
-
Set up environment variables:
JWT_ADMIN_SECRET=your_admin_secret JWT_USER_SECRET=your_user_secret MONGODB_URI=your_mongodb_connection_string
-
Start the server:
npm start
// Admin Signup
POST /admin/signup
{
"firstName": "string",
"lastName": "string",
"email": "[email protected]",
"password": "string"
}
// Admin Signin
POST /admin/signin
{
"email": "[email protected]",
"password": "string"
}
// Create Course
POST /admin/course
{
"title": "string",
"description": "string",
"price": number,
"imageUrl": "string"
}
// Update Course
PUT /admin/course
{
"courseId": "string",
"title": "string",
"description": "string",
"price": number,
"imageUrl": "string"
}
// User Signup
POST /user/signup
{
"firstName": "string",
"lastName": "string",
"email": "[email protected]",
"password": "string"
}
// Purchase Course
POST /course/purchase
{
"courseId": "string"
}
- Password hashing using bcrypt
- JWT-based authentication
- Input validation using Zod
- Protected routes with middleware authentication
- Separate JWT secrets for admin and user authentication
The API includes comprehensive error handling for:
- Invalid input validation
- Authentication failures
- Database operation errors
- Course creation and update errors
- Purchase verification
Feel free to submit issues and pull requests to improve the API.
This project is licensed under the MIT License - see the LICENSE file for details.