An open API service indexing awesome lists of open source software.

https://github.com/mahesh5726/hackernews-server

"News Moves Fast. So Does This Backend." - Powered by HackerNews-Server
https://github.com/mahesh5726/hackernews-server

api-calls hackernews-api honojs prisma-orm supabase typescript

Last synced: 29 days ago
JSON representation

"News Moves Fast. So Does This Backend." - Powered by HackerNews-Server

Awesome Lists containing this project

README

        

# HackerNews Server

A social media-like backend service built using Node.js and Express with authentication, posts, likes, and comments.

## ๐Ÿ“– Table of Contents
- [Features](#-features)
- [Pre-requisites](#-pre-requisites)
- [Installation](#-installation)
- [Password Hashing](#-password-hashing)
- [Usage](#-usage)
- [API Endpoints](#-api-endpoints)
- [Authentication](#authentication)
- [Users](#users)
- [Posts](#posts)
- [Likes](#likes)
- [Comments](#comments)
- [Folder Structure](#-folder-structure)
- [Contributing](#-contributing)
- [License](#-license)

## ๐Ÿš€ Features
- JWT-based authentication
- CRUD operations for users, posts, likes, and comments
- Middleware-based access control
- Pagination for fetching users, posts, likes, and comments
- sha256 password hashing for security

## ๐Ÿ”ง Pre-requisites
Before running this project, ensure you have the following installed:
- **Node.js** (latest LTS version recommended)
- **TypeScript** (for type safety and better development experience)
- **Supabase** (for authentication and database management)
- **Prisma** (for ORM and database schema management)

## ๐Ÿ› ๏ธ Installation

1. Clone the repository:
```sh
git clone https://github.com/Mahesh5726/hackernews-server.git
```
2. Navigate to the project directory:
```sh
cd hackernews-server
```
3. Install dependencies:
```sh
npm install
```
4. Set up environment variables in a `.env` file:
```env
PORT=3000
JWT_SECRET=your_secret_key
SUPABASE_URL=your_supabase_url
SUPABASE_KEY=your_supabase_key
```

## ๐ŸŽฎ Usage

To start the server in development mode:
```sh
npm run dev
```

To start the server in production mode:
```sh
npm start
```

By default, the server runs on `http://localhost:3000/`.

## ๐Ÿ“Œ API Endpoints

### Authentication
- `GET /auth/sign-in` โ€“ Signs up a user (leverages JWT).
- `GET /auth/log-in` โ€“ Logs in a user (leverages JWT).

### Users
- `GET /users/me` โ€“ Returns the current user's details (based on JWT token).
- `GET /users` โ€“ Returns all users in alphabetical order (paginated).

### Posts
- `GET /posts` โ€“ Returns all posts in reverse chronological order (paginated).
- `GET /posts/me` โ€“ Returns current user's posts (reverse chronological, paginated).
- `POST /posts` โ€“ Creates a post (authored by the current user).
- `DELETE /posts/:postId` โ€“ Deletes the post (if owned by the user).

### Likes
- `GET /likes/on/:postId` โ€“ Fetches likes on a post (reverse chronological, paginated).
- `POST /likes/on/:postId` โ€“ Creates a like (one per user per post).
- `DELETE /likes/on/:postId` โ€“ Deletes a user's like on a post.

### Comments
- `GET /comments/on/:postId` โ€“ Fetches comments on a post (reverse chronological, paginated).
- `POST /comments/on/:postId` โ€“ Creates a comment on a post.
- `DELETE /comments/:commentId` โ€“ Deletes a user's comment.
- `PATCH /comments/:commentId` โ€“ Updates a user's comment.

## ๐Ÿค Contributing

1. Fork the repository.
2. Create a new branch (`git checkout -b feature-branch`).
3. Make your changes and commit (`git commit -m 'Add new feature'`).
4. Push to the branch (`git push origin feature-branch`).
5. Open a Pull Request.

## ๐Ÿ“œ License

This project is licensed under the MIT License - see the [LICENSE](./LICENSE.txt) file for details.

---

๐ŸŒ "Because every great discussion starts with a rock-solid backendโ€”engineered for the front page!"