Skip to content

A simple RESTful API built with Node.js, Express, and SQLite that allows users to register, log in, create posts, and comment — secured with JWT authentication.

Notifications You must be signed in to change notification settings

Sonydivya/community-connect-api

Repository files navigation

🌐 Community Connect API

A simple RESTful backend built with Node.js, Express, and SQLite.
Provides user registration/login (JWT), post creation, and commenting. Endpoints are tested with Postman and a Postman collection + environment is included.


🔖 Project Files (high level)

community-connect-api/ │ ├── controllers/ │ ├── userController.js │ ├── postController.js │ └── commentController.js │ ├── middleware/ │ └── auth.js │ ├── routes/ │ ├── userRoutes.js │ ├── postRoutes.js │ └── commentRoutes.js │ ├── app.js ├── db.js ├── community.db # local SQLite DB (ignored by default) ├── .env.example ├── .gitignore ├── package.json ├── community-connect-api.postman_collection.json ├── community-connect-api.postman_environment.json └── README.md


🚀 Features

  • User registration and login with password hashing (bcryptjs)
  • JWT-based authentication for protected routes
  • Create posts, view all posts, add comments, view comments
  • SQLite (file-based) DB; tables auto-created on server start
  • Postman collection + environment included for easy testing

🧰 Tech Stack

  • Node.js, Express
  • SQLite (sqlite3)
  • jsonwebtoken (JWT)
  • bcryptjs (password hashing)
  • dotenv (environment variables)
  • Postman (API testing)

⚙️ Quick Setup (Local)

These commands assume your project is at C:\Users\dell\Desktop\community-connect-api (adjust path if different).

  1. Clone repo (if not already):
git clone https://github.com/your-username/community-connect-api.git
cd community-connect-api

Install dependencies:
npm install

Create a .env from the example:
cp .env.example .env
# On Windows PowerShell:
# copy .env.example .env

Open .env and set values (replace placeholder secret):
JWT_SECRET=your_long_random_secret_here
PORT=4000
Do not commit .env. The repo includes .env.example (placeholders only)

Start the server:
npm run dev
The server runs at:
👉 http://localhost:4000

You should see:
✅ Database ready (tables created if not present).
✅ Server running on port 4000

📬 API Endpoints
| Method | Endpoint                | Description                 |
| ------ | ----------------------- | --------------------------- |
| POST   | `/api/users/register`   | Register a new user         |
| POST   | `/api/users/login`      | Login and get JWT token     |
| POST   | `/api/posts`            | Create a new post           |
| GET    | `/api/posts`            | Get all posts               |
| POST   | `/api/comments/:postId` | Add a comment to a post     |
| GET    | `/api/comments/:postId` | Get all comments for a post |

🧪 Test with Postman

1.Import these files into Postman:

1.1community-connect-api.postman_collection.json

1.2community-connect-api.postman_environment.json

2.Set environment to Community Connect (Local).

3.Run these requests in order:

3.1 Register

3.2 Login (copy JWT token automatically)

3.3 Create Post

3.4 Get All Posts

3.5 Add Comment

3.6 Get Comments

🗄️ Database

SQLite database (community.db)
Tables auto-created when the server starts

🧰 Tech Stack

Node.js

Express

SQLite

JWT Authentication

bcryptjs

dotenv

Postman (for testing)

🧑‍💻 Author

Divya Pasupuleti
📫 Email: your.email@example.com

💻 GitHub: https://github.com/your-username

About

A simple RESTful API built with Node.js, Express, and SQLite that allows users to register, log in, create posts, and comment — secured with JWT authentication.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published