A Node.js and Express-based backend for a blogging platform with features like user authentication, blog creation, publishing, and comments.
Frontend Repository: blogs-frontend
- User Authentication: JWT-based authentication with session management
- Blog Management: Create, read, update, and delete blog posts
- Publishing: Schedule blog posts for automatic publishing using cron jobs
- Image Upload: Integration with Cloudinary for image hosting
- Comments: Allow users to comment on blog posts
- CORS: Cross-origin resource sharing for frontend integration
- Database: MongoDB with Mongoose ORM
- Node.js - JavaScript runtime
- Express.js - Web framework
- MongoDB - NoSQL database
- Mongoose - ODM (Object Data Modeling)
- JWT - JSON Web Token for authentication
- Cloudinary - Image hosting service
- Multer - File upload middleware
- Node-Cron - Job scheduler
- Groq SDK - AI integration
- Clone the repository:
git clone <repository-url>
cd backend- Install dependencies:
npm install- Create a
.envfile in the root directory and add your environment variables:
PORT=3000
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
CLOUDINARY_NAME=your_cloudinary_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret
npm run devnpm startThe server will start on http://localhost:3000 (or the port specified in .env)
├── ConnectDB.js # Database connection setup
├── index.js # Main application entry point
├── package.json # Project dependencies
├── services.js # Business logic services
├── controllers/ # Request handlers
│ ├── blog.js # Blog controllers
│ └── publish-blog.js # Blog publishing and scheduling
├── middlewares/ # Express middlewares
│ └── authentication.js # JWT authentication middleware
├── models/ # Mongoose schemas
│ ├── blogs.js # Blog schema
│ ├── comments.js # Comments schema
│ └── user.js # User schema
├── public/ # Static files
├── routes/ # API routes
│ ├── blog.js # Blog routes
│ └── user.js # User routes
├── uploads/ # Uploaded files directory
└── utils/ # Utility functions
├── cloudinary.js # Cloudinary configuration
└── multer.js # Multer configuration
- User authentication and management endpoints
- Blog CRUD operations
- Blog publishing and scheduling
- Comments management
The application uses JWT-based authentication. The auth token is stored in cookies and validated on protected routes using the checkForAuthCookie middleware.
Images are uploaded to Cloudinary through the Multer middleware. Configuration is in utils/multer.js.
Blog posts can be scheduled for automatic publishing using Node-Cron. The scheduler is initialized in publish-blog.js controller.
PORT- Server port (default: 3000)MONGODB_URI- MongoDB connection stringJWT_SECRET- Secret key for JWT signingCLOUDINARY_NAME- Cloudinary account nameCLOUDINARY_API_KEY- Cloudinary API keyCLOUDINARY_API_SECRET- Cloudinary API secret
This project is licensed under the ISC License.
For frontend repository, visit: blogs-frontend