README.md
This project is a content streaming platform built with the MERN (MongoDB, Express, React, Node.js) stack. It allows users to upload, stream, and comment on videos.
- Prerequisites
- Installation
- Environment Variables
- Usage
- Obtaining JWT Token
- Handling Uploads
- Project Structure
- Contributing
- License
Before you begin, ensure you have met the following requirements:
- Node.js: Download and install Node.js from Node.js official website.
- MongoDB: Set up a MongoDB database. You can use a local instance or a cloud-based solution like MongoDB Atlas.
- Cloudinary Account: Sign up for a Cloudinary account for video storage and streaming.
-
Clone the repository:
git clone https://github.com/talvinder/social-content-streaming-platform.git cd social-content-streaming-platform
-
Install server dependencies:
cd backend npm install
-
Install client dependencies:
cd ../frontend npm install
-
Clone the repository:
git clone https://github.com/talvinder/social-content-streaming-platform.git cd social-content-streaming-platform
-
Install server dependencies:
cd backend npm install
-
Install client dependencies:
cd ../frontend npm install
Create a .env
file in the backend
directory and add your environment variables. You can use the .env.example
file as a template.
backend/.env
PORT=5000
MONGODB_URI=mongodb://localhost:27017/content-platform
JWT_SECRET=your_jwt_secret
CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret
-
Start the MongoDB server (if using a local instance):
mongod
-
Start the backend server:
cd backend npm start
-
Start the frontend development server:
cd frontend npm start
-
Open your browser and navigate to
http://localhost:3000
To authenticate and obtain a JWT token, you need to register and log in:
-
Register:
-
Send a POST request to
http://localhost:5000/api/auth/register
with the following JSON body:{ "username": "your_username", "password": "your_password" }
-
-
Log in:
-
Send a POST request to
http://localhost:5000/api/auth/login
with the following JSON body:{ "username": "your_username", "password": "your_password" }
-
The response will contain a JWT token:
{ "token": "your_jwt_token", "user": { "_id": "user_id", "username": "your_username" } }
-
Since the uploads
folder is not included in the repository, you need to create it manually. This folder is used to store uploaded files temporarily before they are processed.
-
Create the
uploads
folder:mkdir backend/uploads
-
Download a Sample Video:
- Download a sample video from Pexels and place it in the
uploads
folder to test the upload functionality.
- Download a sample video from Pexels and place it in the
social-content-streaming-platform/
├── backend/
│ ├── controllers/
│ │ ├── videoController.js
│ │ └── authController.js
│ ├── middleware/
│ │ └── auth.js
│ ├── models/
│ │ ├── Video.js
│ │ ├── User.js
│ │ └── Comment.js
│ ├── routes/
│ │ ├── videoRoutes.js
│ │ └── authRoutes.js
│ ├── uploads/ (not committed to the repo)
│ ├── .env.example
│ ├── .gitignore
│ ├── server.js
│ └── package.json
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ │ ├── Navbar.js
│ │ │ ├── Home.js
│ │ │ ├── Login.js
│ │ │ ├── Register.js
│ │ │ ├── VideoPlayer.js
│ │ │ ├── CommentForm.js
│ │ │ └── CommentList.js
│ │ ├── App.js
│ │ ├── index.js
│ ├── .gitignore
│ └── package.json
├── .gitignore
└── README.md
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/your-feature
). - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
This section explains the logic and functionality of the main parts of the code.
The server.js
file is the entry point for the backend application. It sets up the Express server, connects to MongoDB, and defines the routes.
- Express Setup: Initializes the Express app and sets up middleware for JSON parsing and CORS.
- MongoDB Connection: Connects to MongoDB using Mongoose.
- Routes: Defines the routes for authentication and video-related operations.
This file contains the logic for video-related operations, including uploading videos to Cloudinary, streaming videos, fetching video details, and handling comments.
- uploadVideo: Handles video uploads by saving the file to Cloudinary and creating a new video document in MongoDB.
- streamVideo: Redirects to the Cloudinary URL for streaming the video.
- getVideos: Fetches a list of all videos.
- getVideoById: Fetches details of a specific video by its ID.
- getCommentsByVideoId: Fetches comments for a specific video.
- addComment: Adds a comment to a video.
This file contains the logic for user authentication, including registration and login.
- register: Creates a new user with a hashed password and saves it to MongoDB.
- login: Authenticates a user by comparing the provided password with the stored hashed password and returns a JWT token if successful.
This file contains the middleware for verifying JWT tokens. It ensures that only authenticated users can access certain routes.
- auth: Verifies the JWT token and attaches the decoded user information to the request object.
This directory contains the Mongoose models for the application.
- User.js: Defines the schema for user documents, including username and password.
- Video.js: Defines the schema for video documents, including title, description, URL, and user reference.
- Comment.js: Defines the schema for comment documents, including text, user reference, and video reference.
This directory contains the React components for the frontend application.
- Navbar.js: Displays the navigation bar.
- Home.js: Displays the homepage with a list of videos.
- Login.js: Provides a form for user login.
- Register.js: Provides a form for user registration.
- VideoPlayer.js: Displays a video player with the video details, like button, and comments.
- CommentForm.js: Provides a form for adding comments to a video.
- CommentList.js: Displays a list of comments for a video.
The main component that sets up the routes using React Router.
The entry point for the React application. It renders the App component.
By following the steps outlined in this README, you can set up and run the social content streaming platform on both Linux and Windows platforms. The backend and frontend components are explained in detail to help you understand the logic and functionality of the code. If you have any questions or need further assistance, feel free to open an issue or contribute to the project.