Skip to content

DevBlogs : A blogging website made for developers by developers. This repository contains the backend for the project

License

Notifications You must be signed in to change notification settings

MLSAKIIT/devblogs-backend

Repository files navigation

DevBlogs Backend

Overview

This is the backend API for DevBlogs, a Full Stack Blogging site for Developers by Developers. It's part of the MLSA HACKTOBER 2024: WEBDEV project.

Tech Stack

  • Express.js as the web application framework
  • MongoDB for database management
  • Mongoose for MongoDB object modeling
  • JSON Web Tokens (JWT) for authentication

Features

  1. User authentication and authorization
  2. Blog post creation and retrieval
  3. Pagination for blog posts
  4. Request body validation
  5. Rate limiting
  6. CORS protection

Prerequisites

  • Node.js
  • npm or yarn
  • MongoDB

Getting Started

  1. Clone the repository to your local machine.
  2. Navigate to the backend directory of the project.
  3. Install the required dependencies:
    npm install
    
    or
    yarn install
    
  4. Set up your environment variables:
    • Create a .env file in the backend directory.
    • Add necessary variables such as MONGODB_URI and JWT_SECRET.
  5. Start the server:
    npm run dev
    
    or
    yarn dev
    
  6. The backend should now be running, typically on http://localhost:3000.

Folder Structure

.
├── controllers/
│   └── auth.js
├── index.js
├── models/
│   ├── Blogs.js
│   └── User.js
├── package.json
├── routes/
│   ├── auth.js
│   └── blog.js
└── utils/
    └── jwtHelper.js

API Routes

  • /register: User registration
  • /login: User login
  • /get-blogs: Retrieve blog posts (with pagination)
  • /create-blog: Create a new blog post (protected route)
  • /get-featured-blog: Retrieve featured blog posts
  • /verify: Verify JWT token

For detailed API documentation, refer to the Swagger documentation (to be implemented).

Contributing

We welcome contributions to improve this project! Here's how you can contribute:

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

Issues & Features

  • User authentication with hashed passwords.
  • Input validation with joi.
  • Rate limiting and CORS protection.
  • Route protection using middleware.
  • Swagger for API documentation.
  • Error handling middleware.

Check the main project documentation for a list of current issues and tasks for the backend.

References