A robust and scalable RESTful API backend for a course selling platform built with Node.js, Express, and MongoDB. This application provides comprehensive user authentication, admin course management, and purchase tracking capabilities.
- User Authentication: Secure signup and signin with JWT tokens
- Admin Authentication: Separate admin authentication system with elevated privileges
- Token-based Security: JSON Web Tokens for secure API access
- User registration and login
- View purchased courses
- Purchase course functionality
- Admin registration and login
- Create and manage courses
- Course content management (title, description, price, images)
- Course creation and listing
- Course preview for users
- Purchase tracking and management
- Backend: Node.js, Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (JSON Web Tokens)
- Development: Nodemon for hot reloading
- Node.js (v14 or higher)
- MongoDB database
- npm or yarn
-
Clone the repository
git clone <repository-url> cd course-selling-backend
-
Install dependencies
npm install
-
Environment Setup
- Update the MongoDB connection string in
index.js - Configure JWT secrets in
config/config.js
- Update the MongoDB connection string in
-
Start the application
# Development mode npm run dev # Production mode npm start
The server will start on http://localhost:3000
POST /user/signup- Register a new userPOST /user/signin- User loginGET /user/purchases- View purchased coursesPOST /user/purchases- Purchase a course
POST /admin/signup- Register a new adminPOST /admin/signin- Admin loginPOST /admin/course- Create a new course (admin only)GET /admin/course- View courses (admin only)
GET /course/preview- Preview available coursesPOST /course/purchases- Purchase a course
course-selling-backend/
├── config/
│ └── config.js # JWT configuration
├── db/
│ └── db.js # Database models and schemas
├── middlewares/
│ ├── admin.middleware.js # Admin authentication middleware
│ └── user.middlewares.js # User authentication middleware
├── routes/
│ ├── admin.route.js # Admin-related routes
│ ├── courses.route.js # Course-related routes
│ └── user.route.js # User-related routes
├── index.js # Main application entry point
├── package.json # Project dependencies and scripts
└── README.md # This file
{
email: String (unique),
password: String,
firstname: String,
lastName: String
}{
email: String (unique),
password: String,
firstname: String,
lastName: String
}{
title: String,
desc: String,
price: Number,
imageUrl: String,
creatorId: ObjectId
}{
userId: ObjectId,
courseId: ObjectId
}The application uses the following configuration:
- Database: MongoDB connection string in
index.js - JWT Secrets: User and admin JWT passwords in
config/config.js
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License - see the package.json file for details.
If you encounter any issues or have suggestions, please create an issue in the repository.
For any queries or collaboration, please reach out through the repository issues section.
Built with ❤️ using Node.js and Express