Skip to content

notnayan/blog-platform-api

Repository files navigation

📝 Blog Platform API

A RESTful API built using Node.js, Express and MongoDB.

🌟 Features

  • User Authentication

    • Register & Login with hashed passwords and JWT token generation.
    • Protected routes with middleware-based token validation.
  • Blog Management (CRUD)

    • Create, read, update and delete blog posts.
    • Each blog contains a title, description, optional tags and creation date.
  • Advanced Features

    • Add comments to blogs.
    • Tag-based filtering.
    • Text-based search (title & description).
    • Sorting blogs by creation date (asc/desc).
    • Pagination with ?page and ?limit query support.
  • Validation & Error Handling

    • Input validation using simple schema checks.
    • Centralized error handling using Express middleware.
  • Code Structure

    • Organized into controllers, routes, models, middlewares and config.

🛠️ Technologies Used

  • Node.js
  • Express.js
  • MongoDB & Mongoose
  • bcryptJS
  • dotenv
  • express-validator
  • jsonwebtoken (JWT)
  • nodemon

🚀 Getting Started

1. Clone the Repository

git clone https://github.com/notnayan/blog-platform-api
cd blog-platform-api

2. Install Dependencies

npm install

3. Environment Variables

Create a .env file in the root and add your environment variables. Use the provided .env.example as a reference:

PORT= your_port
MONGODB_CONNECTION_STRING= your_mongodb_connection_string
JWT_SECRET_KEY= your_secret_key

4. Run the Server

npm run dev

Server will start at http://localhost:PORT

📬 API Endpoints Overview

🔐 Auth Routes

Method Endpoint Description
POST /api/auth/register New user registration
POST /api/auth/login User logs in

📝 Blog Routes (Protected)

Method Endpoint Description
POST /api/blogs Create a blog
GET /api/blogs Get all blogs
GET /api/blogs/:id Get blog by ID
PUT /api/blogs/:id Update a blog
DELETE /api/blogs/:id Delete a blog
POST /api/blogs/:id/comments Add a comment

📌 Note:
The GET /api/blogs endpoint supports the following optional query parameters:

  • search — Search by title or description (e.g. ?search=javascript)
  • tag — Filter blogs by a specific tag (e.g. ?tag=nodejs)
  • sort — Sort by creation date (asc or desc) (e.g. ?sort=desc)
  • page & limit — Pagination support (e.g. ?page=2&limit=5)

You can combine them as needed, like:
/api/blogs?search=node&tag=backend&sort=desc&page=1&limit=10

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors