This is a simple Course Management System built with Node.js, Express, and MongoDB. It provides separate routes for administrators and users, allowing course creation, user registration, and course purchases.
- User authentication (signup and signin)
- Admin authentication (signup and signin)
- Course creation and listing (admin only)
- Course purchasing (users)
- Viewing purchased courses (users)
Ensure you have Node.js installed on your system. You can download it from nodejs.org.
- Clone the repository:
git clone <repository-url>
- Navigate to the project directory:
cd <project-directory>
- Install the required dependencies:
npm install
-
Set up your MongoDB database:
- This project uses MongoDB Atlas. Make sure you have a MongoDB Atlas account and a cluster set up.
- In the
db/index.js
file, replace the connection string with your own:mongoose.connect("mongodb+srv://<username>:<password>@<your-cluster-url>/<database-name>")
- Replace
<username>
,<password>
,<your-cluster-url>
, and<database-name>
with your actual MongoDB Atlas credentials and chosen database name.
-
Configure the JWT secret:
- The project uses a hardcoded JWT secret. In a production environment, it's recommended to use an environment variable instead. You can set it up in a
.env
file:JWT_SECRET=manish12
- The project uses a hardcoded JWT secret. In a production environment, it's recommended to use an environment variable instead. You can set it up in a
Start the server with:
node index.js
The server will run on port 3000 by default.
The project uses the following MongoDB schemas:
const AdminSchema = new mongoose.Schema({
username: String,
password: String
});
const CourseSchema = new mongoose.Schema({
title: String,
description: String,
price: Number,
imgLink: String
});
const UserSchema = new mongoose.Schema({
username: String,
password: String,
courses: [CourseSchema]
});
POST /admin/signup
: Create a new admin accountPOST /admin/signin
: Sign in as an adminPOST /admin/courses
: Create a new course (requires admin authentication)GET /admin/courses
: List all courses (requires admin authentication)
POST /user/signup
: Create a new user accountPOST /user/signin
: Sign in as a userGET /user/courses
: List all available coursesPOST /user/courses/:courseId
: Purchase a course (requires user authentication)GET /user/purchasedCourses
: List purchased courses (requires user authentication)
This project uses JWT (JSON Web Tokens) for authentication. Include the token in the Authorization header of your requests:
Authorization: Bearer <your_token_here>
index.js
: Main application fileroutes/
:admin.js
: Admin routesuser.js
: User routes
middleware/
:admin.js
: Admin authentication middlewareuser.js
: User authentication middleware
db/
:index.js
: Database models and connection
Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs or improvements.
This project is open source and available under the MIT License.