An automated system for generating human-like blog posts for social media niches using n8n workflow.
This project combines Next.js REST API service with n8n workflows to create an automated blog post generation system. It leverages various AI services and APIs to generate high-quality, unique content with built-in similarity checking to avoid duplicates.
- Backend API: Next.js with MongoDB
- Workflow Automation: n8n
- AI Services:
- OpenAI API (for embeddings and content generation)
- Anthropic API (for human-like blog writing)
- Google Serper API (for keyword research)
- Perplexity Research API (optional, for topic research)
- Storage: AWS S3 (for saving blog images)
- Tunnel: ngrok (for exposing local API)
n8n-blog-rest-api/: Next.js REST API service with RAG functionalityn8n-config/: n8n workflow configurations and Docker setup
- Navigate to
n8n-blog-rest-api/:
cd n8n-blog-rest-api
npm install- Configure environment variables:
- Copy
.example.envto.env - Fill in the required variables:
- Copy
OPENAI_API_KEY=your_openai_api_key
MONGO_URL=mongodb+srv://${DB_USER_NAME}:${DB_PASSWORD}@cluster0.smdgg5t.mongodb.net/spybroski
SERVICE_API_KEY=your_generated_api_key (openssl rand -hex 32)
NEXT_PUBLIC_HOST=your_ngrok_url # Will be updated after ngrok setup- Start the service:
npm run devSince the local Next.js API needs to be accessible from the internet, we'll use ngrok to create a secure tunnel.
- Install ngrok:
# Using npm
npm install -g ngrok
# Or using Homebrew on macOS
brew install ngrok-
Sign up for a free ngrok account at https://ngrok.com and get your authtoken
-
Configure ngrok:
ngrok config add-authtoken your_authtoken- Start ngrok tunnel:
ngrok http 3000- Update your environment variables:
- Copy the HTTPS URL provided by ngrok (e.g.,
https://your-domain.ngrok.io) and use inn8n-config/blog-workflow.jsonwhen specifying service host
- Copy the HTTPS URL provided by ngrok (e.g.,
For more details about ngrok setup and features, visit: ngrok Documentation
-
Navigate to
n8n-config/ -
Configure the workflow:
- Open
blog-workflow.json - Replace
${YOUR_HOST}with your ngrok URL - Replace
${YOUR_API_KEY}with yourSERVICE_API_KEY - Replace
${YOUR_GOOGLE_SERPER_API_KEY}with your${YOUR_GOOGLE_SERPER_API_KEY}(https://serper.dev/)
- Open
-
Go back to root directory and Start n8n using Docker:
docker compose up -d- Access n8n:
- Open
http://localhost:5678/workflow/ - Import
blog-workflow.json(https://ibb.co/YBnmPCC8) - Configure API keys for all services:
- OpenAI
- Google Serper
- Anthropic
- AWS S3
- Other service providers as needed
- Open
GET /api/blogs/latest: Retrieve latest blog postsPOST /api/blogs/check-similarity: Check if similar blog content existsPOST /api/blogs: Create new blog postGET /api/blogs/[slug]: Get specific blog by SEO-optimized slugGET /api/blogs: Get all blogs
The n8n workflow handles:
- Topic research and keyword optimization
- Blog title and meta generation
- SEO-friendly slug creation
- Blog cover image prompt generation
- Human-like content creation using Anthropic AI
- Image storage in AWS S3
- Content similarity checking
- Database storage
- OpenAI API key
- Google Serper API key (free with registration) (https://serper.dev/)
- Anthropic API key
- AWS S3 credentials
- MongoDB connection string
- Perplexity Research API key
- Start the REST API service (runs on port 3000)
- Start ngrok tunnel to expose your API
- Launch n8n using Docker (available on port 5678)
- Import and configure the workflow in n8n
- Execute the workflow to start generating content
Important Notes:
- The ngrok URL changes every time you restart the tunnel unless you have a paid plan
- Update your
NEXT_PUBLIC_HOSTand n8n workflow configuration whenever the ngrok URL changes - For production use, consider using a paid ngrok plan or a proper reverse proxy setup
For detailed customization options and advanced configurations, refer to the individual service directories.
