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
- Host: GitHub
- URL: https://github.com/mahesh5726/hackernews-server
- Owner: Mahesh5726
- License: mit
- Created: 2025-03-26T04:11:17.000Z (about 1 month ago)
- Default Branch: master
- Last Pushed: 2025-04-04T06:52:45.000Z (29 days ago)
- Last Synced: 2025-04-04T07:23:07.245Z (29 days ago)
- Topics: api-calls, hackernews-api, honojs, prisma-orm, supabase, typescript
- Language: TypeScript
- Homepage:
- Size: 67.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
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!"