The backend_hono project is a Node.js Backend API built with Hono and MongoDB, designed to provide a robust solution for managing favorite YouTube videos. This application allows users to create, read, update, and delete their favorite video entries, leveraging the power of MongoDB for data persistence and Hono for a lightweight API framework.
- CRUD Operations: Create, Read, Update, and Delete operations for favorite YouTube videos.
- Streaming Capabilities: Stream video descriptions in real-time.
- API Integration: RESTful API endpoints for easy integration with other applications.
- MongoDB Integration: Utilizes MongoDB for data storage, ensuring scalability and performance.
- Modular Structure: Organized codebase for easy maintenance and scalability.
| Method | Endpoint | Description |
|---|---|---|
| GET | / | Retrieve all favorite videos |
| POST | / | Add a new favorite video |
| GET | /:documentId | Retrieve a specific video by ID |
| PATCH | /:documentId | Update an existing video |
| DELETE | /:documentId | Remove a video |
| GET | /d/:documentId | Stream video description character by character |
Request:
curl -X POST http://localhost:3000/api/videos -H "Content-Type: application/json" -d '{"title":"Sample Video","description":"This is a sample video description","youtubeName":"Sample Channel"}'Response:
{
"title": "Sample Video",
"description": "This is a sample video description",
"youtubeName": "Sample Channel",
"_id": "60d5ec49f5f1f0b1b2c0c0a0",
"createdAt": "2023-07-01T00:00:00Z",
"updatedAt": "2023-07-01T00:00:00Z"
}Request:
curl http://localhost:3000/api/videosResponse:
[
{
"title": "Sample Video",
"description": "This is a sample video description",
"youtubeName": "Sample Channel",
"_id": "60d5ec49f5f1f0b1b2c0c0a0"
}
]Before you begin, ensure you have the following installed:
- Node.js (v14 or later) β Download here
- MongoDB β Set up a MongoDB instance locally or use a cloud service.
- TypeScript β Install globally via npm:
npm install -g typescript
- Package Manager (pnpm or npm) β Install pnpm globally:
npm install -g pnpm
-
Clone the repository:
git clone https://github.com/yourusername/backend_hono.git cd backend_hono/my-app -
Install dependencies:
pnpm install
-
Environment Setup: Create a
.envfile in the root of themy-appdirectory and set the required environment variables. Example:MONGO_URI=your_mongodb_connection_string
To start the application, run:
pnpm startHere are example API requests using curl:
-
Add a Favorite Video:
curl -X POST http://localhost:3000/api/videos -H "Content-Type: application/json" -d '{"title":"Sample Video","description":"This is a sample video description","youtubeName":"Sample Channel"}'
-
Get All Videos:
curl http://localhost:3000/api/videos
For a successful video addition, you would receive a response like:
{
"title": "Sample Video",
"description": "This is a sample video description",
"youtubeName": "Sample Channel",
"_id": "60d5ec49f5f1f0b1b2c0c0a0",
"createdAt": "2023-07-01T00:00:00Z",
"updatedAt": "2023-07-01T00:00:00Z"
}The main collection fav-youtube-videos consists of documents with the following fields:
- title: string (required)
- description: string (required)
- thumbnailUrl: string (optional, default: "default_thumbnail.png")
- watched: boolean (required, default: false)
- youtubeName: string (required)
The Mongoose schema for favorite YouTube videos is defined in src/db/fav-youtube-model.ts and includes validations to ensure data integrity.
The project structure is organized as follows:
/
βββ README.md # Project documentation
βββ image.png # Placeholder image
βββ my-app # Main application directory
β βββ .gitignore # Git ignore rules
β βββ bun.lockb # Bun lock file
β βββ package.json # Project dependencies and scripts
β βββ pnpm-lock.yaml # pnpm lock file
β βββ src # Source files
β β βββ db # Database models
β β βββ index.ts # Main entry point
β β βββ learn.ts # Learning functionality
β βββ tsconfig.json # TypeScript configuration
βββ package.json # Root package configuration
package.json: Contains project dependencies including Hono, Mongoose, and UUID.src/index.ts: Main entry point that sets up the Hono API server with MongoDB connection.src/db/connect.ts: MongoDB connection utility.src/db/fav-youtube-model.ts: Mongoose schema for favorite YouTube video data.src/learn.ts: Example module with in-memory CRUD operations for learning purposes.
- Clone the repository and navigate to the
my-appdirectory. - Install dependencies using
pnpm install.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create your 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.
To deploy this application:
- Set up your production environment with Node.js and MongoDB.
- Ensure environment variables are correctly set in your production server.
- Use a process manager like PM2 to run the application in production.
- Use the latest stable version of Node.js.
- Ensure MongoDB is configured for production use with proper authentication.
This project is licensed under the MIT License. See the LICENSE file for details.
- Author: Your Name
- Contact: yourname@example.com
This README was generated by GitDox Agent.