Skip to content

deepeshAg/backend_hono

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ backend_hono

TypeScript Hono Mongoose MongoDB Node.js

πŸš€ Project Overview

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.

🌟 Features

  • 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.

πŸš€ API Endpoints

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 and Response Examples

1. Add a Favorite Video

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"
}

2. Get All Videos

Request:

curl http://localhost:3000/api/videos

Response:

[
  {
    "title": "Sample Video",
    "description": "This is a sample video description",
    "youtubeName": "Sample Channel",
    "_id": "60d5ec49f5f1f0b1b2c0c0a0"
  }
]

πŸ“¦ Installation

Prerequisites

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

Step-by-Step Setup

  1. Clone the repository:

    git clone https://github.com/yourusername/backend_hono.git
    cd backend_hono/my-app
  2. Install dependencies:

    pnpm install
  3. Environment Setup: Create a .env file in the root of the my-app directory and set the required environment variables. Example:

    MONGO_URI=your_mongodb_connection_string
    

πŸ’» Usage

Starting the Server

To start the application, run:

pnpm start

Example API Requests

Here 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

Example Response Formats

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"
}

πŸ“Š Database Schema

MongoDB Collection Structure

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)

Mongoose Schema Fields and Validations

The Mongoose schema for favorite YouTube videos is defined in src/db/fav-youtube-model.ts and includes validations to ensure data integrity.

πŸ—οΈ Project Structure

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

Key Files and Their Purpose

  • 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.

πŸ”§ Development

Setting Up Development Environment

  1. Clone the repository and navigate to the my-app directory.
  2. Install dependencies using pnpm install.

Contribution Guidelines

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a pull request.

πŸš€ Deployment

Instructions for Deploying to Production

To deploy this application:

  1. Set up your production environment with Node.js and MongoDB.
  2. Ensure environment variables are correctly set in your production server.
  3. Use a process manager like PM2 to run the application in production.

Recommended Environment Settings

  • Use the latest stable version of Node.js.
  • Ensure MongoDB is configured for production use with proper authentication.

πŸ“‹ License Information

This project is licensed under the MIT License. See the LICENSE file for details.

✍️ Author/Contributors Information


This README was generated by GitDox Agent.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors