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.
- Express.js as the web application framework
- MongoDB for database management
- Mongoose for MongoDB object modeling
- JSON Web Tokens (JWT) for authentication
- User authentication and authorization
- Blog post creation and retrieval
- Pagination for blog posts
- Request body validation
- Rate limiting
- CORS protection
- Node.js
- npm or yarn
- MongoDB
- Clone the repository to your local machine.
- Navigate to the backend directory of the project.
- Install the required dependencies:
or
npm install
yarn install
- Set up your environment variables:
- Create a
.env
file in the backend directory. - Add necessary variables such as
MONGODB_URI
andJWT_SECRET
.
- Create a
- Start the server:
or
npm run dev
yarn dev
- The backend should now be running, typically on http://localhost:3000.
.
├── controllers/
│ └── auth.js
├── index.js
├── models/
│ ├── Blogs.js
│ └── User.js
├── package.json
├── routes/
│ ├── auth.js
│ └── blog.js
└── utils/
└── jwtHelper.js
/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).
We welcome contributions to improve this project! Here's how you can contribute:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
- 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.
- Mongoose with Express:
- Authentication (JWT):
- Route protection through middleware:
- Dynamic routes in Express:
- Express rate limiting:
- Validation using JOI:
- Pagination:
- Express CORS:
- Error Handling in Express:
- Middlewares: