The Course Selling Fullstack Application is a platform that allows administrators to create and manage online courses, and users to browse, purchase, and access these courses. The backend provides secure authentication for both admins and users, supports course management, and tracks user purchases. The application is built using Node.js, Express, MongoDB, and JWT for authentication, and is designed to be used as the backend for a modern web-based course marketplace.
This backend provides a RESTful API for a course selling platform. It supports user and admin authentication, course management, and course purchasing. The backend is built with Node.js, Express, MongoDB, and uses JWT for authentication.
- JWT tokens are used for authentication.
- For protected routes, add the header:
Authorization: Bearer <token>
- POST
/admin/signup - Body:
{ "firstName": "John", "lastName": "Doe", "email": "admin@example.com", "password": "yourpassword" } - Response:
{ "message": "You are signed up!" }
- POST
/admin/signin - Body:
{ "email": "admin@example.com", "password": "yourpassword" } - Response:
{ "token": "<jwt_token>" }
- POST
/admin/course - Headers:
Authorization: Bearer <admin_token> - Body:
{ "title": "Course Title", "description": "Course Description", "price": 100, "imageURL": "https://example.com/image.jpg" } - Response:
{ "message": "Course created successfully" }
- PUT
/admin/course - Headers:
Authorization: Bearer <admin_token> - Body:
{ "courseId": "<course_id>", "title": "Updated Title", "description": "Updated Description", "price": 120, "imageURL": "https://example.com/newimage.jpg" } - Response:
{ "message": "Course updated successfully" }
- GET
/admin/course - Headers:
Authorization: Bearer <admin_token> - Response:
[ { "_id": "<course_id>", "title": "Course Title", "description": "Course Description", "price": 100, "imageURL": "https://example.com/image.jpg", "creatorId": "<admin_id>", "createdAt": "...", "updatedAt": "..." } ]
- POST
/user/signup - Body:
{ "firstName": "Jane", "lastName": "Smith", "email": "user@example.com", "password": "yourpassword" } - Response:
{ "message": "You are signed up!" }
- POST
/user/signin - Body:
{ "email": "user@example.com", "password": "yourpassword" } - Response:
{ "token": "<jwt_token>" }
- GET
/user/purchases - Headers:
Authorization: Bearer <user_token> - Response:
{ "courses": [ { "_id": "<purchase_id>", "userId": "<user_id>", "courseId": "<course_id>", "createdAt": "...", "updatedAt": "..." } ] }
- GET
/course/preview - Response:
[ { "_id": "<course_id>", "title": "Course Title", "description": "Course Description", "price": 100, "imageURL": "https://example.com/image.jpg", "creatorId": "<admin_id>", "createdAt": "...", "updatedAt": "..." } ]
- POST
/course/purchase - Headers:
Authorization: Bearer <user_token> - Body:
{ "courseId": "<course_id>" } - Response:
{ "message": "Purchased successfully" }
- All errors return a JSON object with a
messageand may include anerrorfield. - Example:
{ "message": "Validation failed", "error": [ ... ] }
| Variable | Description |
|---|---|
| PORT | Port to run the server |
| MONGODB_URI | MongoDB connection string |
| JWT_SECRET_ADMIN | JWT secret for admin tokens |
| JWT_SECRET_USER | JWT secret for user tokens |
For questions or support, contact shathwik30@gmail.com.