A full-stack blog editor application built with React, Node.js, and MongoDB.
- Features
- Tech Stack
- Project Structure
- Getting Started
- Database Configuration
- API Documentation
- Frontend Components
- Development
- Deployment
- Create, read, update, and delete blog posts
- Draft and publish functionality
- Tag management for blog posts
- Real-time autosave
- Responsive design
- Modern UI with TailwindCSS
- MongoDB Atlas integration
- React 18.3.1
- React Router DOM 6.20.0
- TailwindCSS 3.4.1
- Lucide React (for icons)
- React Hot Toast (for notifications)
- Vite (build tool)
- Node.js
- Express.js 4.18.2
- MongoDB/Mongoose
- CORS enabled
- Body Parser
- MongoDB Atlas
- Mongoose ODM
project/
├── src/ # Frontend source code
│ ├── components/ # React components
│ │ ├── BlogCard.tsx # Individual blog preview
│ │ ├── BlogEditor.tsx # Blog creation/editing
│ │ ├── BlogList.tsx # List of blogs
│ │ └── Navbar.tsx # Navigation component
│ ├── hooks/ # Custom React hooks
│ ├── services/ # API services
│ ├── types/ # TypeScript types
│ ├── App.tsx # Main React component
│ └── main.tsx # Application entry point
├── server/ # Backend source code
│ ├── config/ # Server configuration
│ │ └── db.js # MongoDB configuration
│ ├── models/ # Database models
│ │ └── Blog.js # Blog schema
│ └── index.js # Server entry point
└── configuration files # Various config files
- Node.js (v14 or higher)
- MongoDB Atlas account or local MongoDB installation
- npm or yarn package manager
-
Clone the repository: ```bash git clone cd blog-editor ```
-
Install dependencies: ```bash npm install ```
-
Create a .env file in the root directory: ```env MONGODB_URI=your_mongodb_connection_string PORT=3001 ```
-
Start the development servers: ```bash npm run dev:full ```
- Create a MongoDB Atlas account
- Create a new cluster
- Get your connection string
- Add connection string to .env file
Blog Schema: ```javascript { title: { type: String, required: true, trim: true }, content: { type: String, required: true }, tags: [{ type: String, trim: true }], status: { type: String, enum: ['draft', 'published'], default: 'draft' }, timestamps: true } ```
- GET
/api/blogs - Returns all blogs sorted by creation date
- GET
/api/blogs/:id - Returns a specific blog by ID
- POST
/api/blogs/save-draft - Body:
{ "title": "string", "content": "string", "tags": "comma,separated,tags" }
- POST
/api/blogs/publish - Body: Same as save draft
- DELETE
/api/blogs/:id - Removes a blog post
- Rich text editing
- Autosave functionality
- Draft/Publish options
- Tag management
- List view of all blogs
- Filtering by status
- Blog preview cards
- Responsive grid layout
- Blog preview display
- Edit/Delete actions
- Status indicator
- Creation/Update timestamps
```bash
npm run dev:full
npm run dev
npm run server ```
MONGODB_URI: MongoDB connection stringPORT: Backend server port (default: 3001)
- Build the frontend: ```bash npm run build ```
- Deploy the
distdirectory to your hosting service
- Ensure environment variables are set
- Deploy the server directory to your hosting service
- Update CORS settings if necessary
The application includes comprehensive error handling:
- Database connection errors
- API request errors
- Form validation
- Network issues
- Graceful degradation
- MongoDB connection string in environment variables
- CORS enabled
- Input sanitization
- Error message sanitization
- Secure database operations
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License.