- Blog Post Management: Create, read, and delete blog posts.
- AI Content Assistance: Leverage Google Gemini to generate suggestions for blog post titles, subtitles, and content.
- Commenting System: Allow users to comment on blog posts.
- Newsletter Subscription: Enable users to subscribe to a newsletter.
- Admin Dashboard:
- View and manage all blog posts.
- View and manage newsletter subscribers.
- Moderate (delete) comments.
- View site statistics (total posts, comments, subscribers).
- Single Page Application (SPA): A dynamic frontend experience within a single HTML file.
- Backend: Node.js, Express.js
- Database: MongoDB with Mongoose ODM
- AI Integration: Google Generative AI (Gemini API)
- Frontend: HTML, CSS, JavaScript (Vanilla JS)
- Dependencies:
@google/generative-ai
: For interacting with the Gemini API.cors
: For enabling Cross-Origin Resource Sharing.dotenv
: For managing environment variables.express
: Web application framework.mongoose
: MongoDB object modeling.multer
: Middleware for handlingmultipart/form-data
(listed inpackage.json
, specific usage for file uploads not detailed in provided core routes).
hyper-27-blogging-web/
├── models/ # Mongoose schemas (BlogPost.js, Subscriber.js)
├── public/ # Static frontend files (index.html)
├── routes/ # API route definitions (blogRoutes.js)
├── package.json # Project metadata and dependencies
├── server.js # Main Express server setup and entry point
└── .env # (To be created by user) Environment variables
- Node.js (LTS version recommended)
- npm (comes with Node.js)
- MongoDB instance (local or cloud-hosted, e.g., MongoDB Atlas)
- Google Gemini API Key
-
Clone the repository:
git clone https://github.com/hyper-27/blogging-web.git cd blogging-web
-
Install dependencies:
npm install
-
Environment Variables: Create a
.env
file in the root directory of the project. Add the following configuration, replacing the placeholder values with your actual credentials and settings:PORT=5000 MONGODB_URI=your_mongodb_connection_string GEMINI_API_KEY=your_google_gemini_api_key
PORT
: The port on which the server will run (default is 5000).MONGODB_URI
: Your MongoDB connection string.GEMINI_API_KEY
: Your API key for Google Gemini.
-
Run the application:
npm start
The server will start, typically on
http://localhost:5000
(or the port specified in your.env
file). You can access the AI Blog Hub application by navigating to this address in your web browser.
All API routes are prefixed with /api
.
GET /posts
: Retrieve all blog posts.POST /posts
: Create a new blog post.- Body:
{ title, subtitle, content, category, author, email }
- Body:
DELETE /posts/:id
: Delete a specific blog post by its ID.
POST /posts/:postId/comments
: Add a comment to a specific blog post.- Body:
{ author, content }
- Body:
DELETE /posts/:postId/comments/:commentId
: Delete a specific comment from a blog post.
GET /subscribers
: Retrieve all newsletter subscribers (admin).POST /subscribe
: Subscribe an email address to the newsletter.- Body:
{ email }
- Body:
DELETE /subscribers/:id
: Unsubscribe an email address by its ID (admin).
POST /ai-generate
: Generate content suggestions using Google Gemini.- Body:
{ prompt }
- Returns:
{ titles: [], subtitles: [], descriptions: [] }
- Body:
The frontend is a Single Page Application (SPA) served from public/index.html
. It directly interacts with the backend API to provide a dynamic user experience for creating posts, viewing content, managing subscriptions, and accessing admin functionalities.