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
- Swagger for API documentation
- User authentication and authorization
- Blog post creation and retrieval
- Pagination for blog posts
- Request body validation
- Rate limiting
- CORS protection
- API documentation with Swagger
- 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.
- Access the Swagger documentation at http://localhost:3000/api-docs.
-
Clone the repository:
git clone https://github.com/MLSAKIIT/devblogs-backend.git
-
Navigate to the project directory:
cd devblogs-backend
-
Configure your .env file:
Before running Docker, ensure you have correctly set up your environment variables.
-
Run the following command to start the application:
docker compose up -d
.
└── src/
├── controllers/
│ ├── auth.js
│ └── blog.js
├── index.js
├── middlewares/
│ ├── errorHandler.js
│ └── verifyTokenMiddleware.js
├── models/
│ ├── Blogs.js
│ └── User.js
├── routes/
│ ├── auth.js
│ ├── blog.js
│ └── verify.js
├── utils/
│ ├── jwtHelper.js
│ └── rateLimit.js
└── validators/
├── login.js
└── register.js
/register
: User registration/login
: User login/verify
: Verify JWT token/change-password
: Change user password/get-blogs
: Retrieve blog posts (with pagination)/create-blog
: Create a new blog post (protected route)/get-featured-blog
: Retrieve featured blog posts
For detailed API documentation, refer to the Swagger UI at /api-docs
when the server is running.
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:
- Swagger Documentation: