BlogForge API is a robust, scalable RESTful API designed to power modern blogging platforms. This API supports user authentication, post management, commenting, following system, and more.
- π User authentication (JWT-based)
- π Post creation and management
- π¬ Commenting system
- π₯ Follow/Unfollow functionality
- π Search capabilities for posts and users
- π Rate limiting
- π‘οΈ Security features (XSS protection, NoSQL injection prevention)
- Node.js (v14.0.0 or higher)
- MongoDB (v4.0.0 or higher)
- npm or yarn
- Clone the repository:
git clone [repository-url]
cd BlogForge- Install dependencies:
npm install- Create a
.envfile in the root directory with the following variables:
NODE_ENV=development
PORT=3000
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRES_IN=7d
MONGODB_URI=mongodb://localhost:27017/blogforge
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100
LOG_LEVEL=error- Seed the database (optional):
npm run seed- Start the server:
# Development mode
npm run dev
# Production mode
npm startPOST /api/auth/register{
"username": "johndoe",
"email": "john@example.com",
"password": "password123"
}POST /api/auth/login{
"email": "john@example.com",
"password": "password123"
}GET /api/postsPOST /api/posts
Authorization: Bearer {token}{
"title": "My First Post",
"content": "This is the content of my post",
"tags": ["tech", "coding"],
"visibility": "public"
}GET /api/posts/:idPUT /api/posts/:id
Authorization: Bearer {token}{
"title": "Updated Title",
"content": "Updated content"
}DELETE /api/posts/:id
Authorization: Bearer {token}POST /api/posts/:id/like
Authorization: Bearer {token}GET /api/posts/search?q=keyword&tags=tech,coding&author=johndoe&sort=recentPOST /api/comments
Authorization: Bearer {token}{
"content": "This is a comment",
"postId": "post_id_here"
}GET /api/comments/posts/:id/commentsGET /api/usersGET /api/users/:idPATCH /api/users/profile
Authorization: Bearer {token}{
"bio": "Software Developer",
"location": "New York",
"website": "https://example.com",
"interests": ["coding", "technology"]
}GET /api/users/search?q=john&interests=tech&location=NewYorkPOST /api/users/:id/follow
Authorization: Bearer {token}POST /api/users/:id/unfollow
Authorization: Bearer {token}GET /api/users/:id/followersGET /api/users/:id/followingImport the file :
Insomnia_rest_setting.json
- JWT-based authentication
- Password hashing using bcrypt
- Rate limiting for API endpoints
- XSS protection
- NoSQL injection prevention
- Security headers using Helmet
Run the test suite:
npm testRun tests with coverage:
npm run test:coverage{
"status": "success",
"data": {
// Response data here
}
}{
"status": "error",
"message": "Error message here"
}| Variable | Description | Default |
|---|---|---|
| NODE_ENV | Environment mode | development |
| PORT | Server port | 3000 |
| MONGODB_URI | MongoDB connection string | - |
| JWT_SECRET | JWT secret key | - |
| JWT_EXPIRES_IN | JWT expiration time | 7d |
| LOG_LEVEL | Winston logger level | info |
.
βββ controllers/
β βββ authController.js
β βββ commentController.js
β βββ followController.js
β βββ postController.js
β βββ userController.js
βββ middleware/
β βββ auth.js
β βββ errorHandler.js
β βββ rateLimit.js
β βββ security.js
βββ models/
β βββ Comment.js
β βββ Post.js
β βββ User.js
βββ routes/
β βββ auth.js
β βββ comments.js
β βββ posts.js
β βββ users.js
βββ utils/
β βββ auth.js
β βββ logger.js
βββ server.js
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request