This project implements a dynamic web server for an online video-sharing platform. The server allows users to upload videos, manage their profiles, and interact with video content through likes, comments, and more. It provides a RESTful API and uses MongoDB for data storage.
-
Clone the repository:
https://github.com/Oran-Zafrani/MeaTube-Server.git
-
Navigate to the project directory:
cd MeaTube-Server -
Install dependencies:
npm install
-
Set up MongoDB Locally
Ensure MongoDB is installed and running on your local machine. Follow these steps to initialize your local database:
- Create a new MongoDB connection:
- Name the connection 'MeaTubeDB'
- Note your connection string:
- The default is typically
mongodb://localhost:27017/MeaTubeDB
- The default is typically
- Configure your environment:
- Create a
.envfile in the project's root directory - Add the following line to the
.envfile, replacing<your-connection-string>with your actual MongoDB connection string:
Example:MONGODB_URI=<your-connection-string>
MONGODB_URI=mongodb://localhost:27017/MeaTubeDB
- Create a
- Create a new MongoDB connection:
-
Set JWT secret Set the JWT secret in your
.envfile.JWT_SECRET=mySuperSecretKey
-
Set server port (Optional) Set the server port in your
.envfile, default is port 8080:PORT=1234
-
Run the server:
npm start
-
Add the initial content to MeaTubeDB: After running the server, you should get an output in the terminal
connected to MongoDBonce a connection has been successfully made to MongoDB.-
Go to the local MongoDB on your PC, you should have the MeaTubeDB database initialized with four collections: comments, likes, users, and videos.
-
Go to the MeaTubeDB folder in the repository.
-
Import
MeaTubeDB.comments.jsonto the 'comments' collection. -
Import
MeaTubeDB.users.jsonto the 'users' collection. -
Import
MeaTubeDB.videos.jsonto the 'videos' collection. -
Restart the server.
The server will be running locally at http://localhost:8080. The API serves endpoints for video and user interactions, supporting CRUD operations for videos and users.
-
GET /users/:id: Get details about a user by their IDGET /users/username/:username: Get details about a user by their usernameGET /users/channel/:channelname: Get details about a user by their channel namePOST /users: Create a new userPOST /login: Authenticate a user and return a JWT tokenPUT /users/:username: Update details of a user (protected route, requires authentication)DELETE /users/:username: Delete a user (protected route, requires authentication)
GET /videos/:id: Get details of a specific video by its ID (requires weak authentication)GET /videos: Get a list of the top 20 videos, sorted randomlyGET /search: Search for videos by keywordGET /videos/username/:username: Get a list of all videos uploaded by a specific userPOST /videos: Add a new video (protected route, requires authentication)PUT /videos/:id: Update details of a specific video (protected route, requires authentication)DELETE /videos/:id: Delete a specific video by ID (protected route, requires authentication)
GET /videos/:id/likes: Get the number of likes for a specific video (protected route)GET /videos/:id/dislikes: Get the number of dislikes for a specific video (protected route)POST /videos/:id/likes: Like a specific video (protected route)POST /videos/:id/dislikes: Dislike a specific video (protected route)DELETE /videos/:id/likes: Remove a like from a video (protected route)DELETE /videos/:id/dislikes: Remove a dislike from a video (protected route)
GET /videos/:id/comments: Get all comments for a specific video (protected route)POST /videos/:id/comments: Add a comment to a video (protected route)PUT /comments/:id: Update a comment by its ID (protected route)DELETE /comments/:id: Delete a comment by its ID (protected route)
- Video Uploads: Users can upload, view, and manage videos.
- User Authentication: Secure login using JWT (JSON Web Tokens).
- RESTful API: Exposed API for managing users and videos.
- Dynamic Video List: Top videos are displayed in random order.
- Likes and Comments: Users can like/dislike videos and add comments.
- Frontend: React (HTML, CSS, JavaScript)
- Backend: Node.js, Express, Mongoose.
- Database: MongoDB (for data persistence)
- API: RESTful API built with Express
- Project Management: Jira Platform
- The final src codes are wrapped under
releases/**branches. Each one of them refers to a different part of the project. - The static client files are included within this project. The web application is accessible directly from the server URL.
- You can also run the web project from the MeaTube-Web repository simultaneously.
- Ofri Kastenbaum
- Oran Zafrani
- Bar Shwartz
