Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NodeJS Blog API

A simple RESTful API for a blog platform built with Node.js, Express, and MongoDB. It supports user authentication, post creation, image uploads, and tag management.

Features

  • User registration and login with JWT authentication
  • Create, read, update, and delete blog posts
  • Upload images for posts
  • Tag management for posts
  • Input validation and error handling

Technologies Used

  • Node.js
  • Express
  • MongoDB & Mongoose
  • JWT (jsonwebtoken)
  • Multer (file uploads)
  • bcrypt (password hashing)
  • express-validator (input validation)
  • CORS

Installation

  1. Clone the repository:
    git clone <repo-url>
    cd NodeJS-Project-main
  2. Install dependencies:
    npm install
  3. Set up MongoDB:
    • Update the MongoDB connection string in index.js if needed.
  4. Start the server:
    npm start
    For development with auto-reload:
    npm run start:dev

API Endpoints

Auth

  • POST /auth/register — Register a new user
  • POST /auth/login — Login and receive JWT token
  • GET /auth/me — Get current user info (requires auth)

Posts

  • GET /posts — Get all posts
  • GET /posts/:id — Get a single post by ID
  • POST /posts — Create a new post (requires auth)
  • PATCH /posts/:id — Update a post (requires auth)
  • DELETE /posts/:id — Delete a post (requires auth)

Tags

  • GET /tags — Get last tags
  • GET /posts/tags — Get last tags

Uploads

  • POST /upload — Upload an image (requires auth)
  • GET /uploads/:filename — Access uploaded images

Project Structure

index.js                # Main server file
package.json            # Project metadata and dependencies
validations.js          # Input validation rules
controllers/            # Route controllers
  index.js
  PostController.js
  UserController.js
models/                 # Mongoose models
  Post.js
  User.js
uploads/                # Uploaded images
utils/                  # Utility functions
  checkAuth.js
  handleValidationErrors.js
  index.js

Usage Notes

  • All protected routes require a valid JWT token in the Authorization header.
  • Images are stored in the uploads/ directory and served statically.
  • Input validation is handled using express-validator.

License

ISC

About

This is the BackEnd part of the Web application developed in React JS

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages