Quick guide to set up and run your RAG backend API for local testing with your portfolio chatbot frontend.
- Node.js (v16 or higher)
- Google AI API key (for Gemini)
- Pinecone account and API key
cd portfolio-chatbot-apinpm install# Copy the example file
cp .env.example .env
# Edit .env file with your API keysYour .env file should contain:
# Google AI API Key for Gemini LLM
GOOGLE_AI_API_KEY=your_gemini_api_key_here
# Pinecone Vector Database Configuration
PINECONE_API_KEY=your_pinecone_api_key_here
PINECONE_INDEX=your_pinecone_index_name_here
# Server Configuration
PORT=3000
NODE_ENV=development
# Frontend URL for CORS
FRONTEND_URL=http://localhost:3000# Update with your personal content
npm run update-content
# Seed the vector database
npm run seednpm run devThe API will be running on http://localhost:3000
POST http://localhost:3000/api/chat
Content-Type: application/json
Body:
{
"message": "Tell me about your projects"
}
Response:
{
"response": "AI-generated response about your portfolio..."
}
GET http://localhost:3000/health
Response:
{
"status": "healthy",
"timestamp": "2025-01-07T06:17:26.000Z",
"service": "portfolio-chatbot-api"
}
POST http://localhost:3000/api/search
Content-Type: application/json
Body:
{
"query": "projects",
"topK": 5
}
Response:
{
"results": [...]
}
To connect your frontend, make HTTP requests to the chat endpoint:
const response = await fetch('http://localhost:3000/api/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: 'Your user message here'
})
});
const data = await response.json();
console.log(data.response); // AI response# Health check
curl http://localhost:3000/health
# Test chat
curl -X POST http://localhost:3000/api/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello"}'# There's already a test script included
.\test-api.ps1The API accepts requests from any origin by default. For production, update FRONTEND_URL in your .env file to your specific domain.
- Port 3000 in use: Change
PORTin.envfile - CORS errors: Verify
FRONTEND_URLsetting - API key errors: Double-check your Gemini and Pinecone keys
- Empty responses: Make sure you've run the seeding steps
Once the server is running and you see:
🚀 Portfolio Chatbot API server running on port 3000
📍 Health check: http://localhost:3000/health
💬 Chat endpoint: http://localhost:3000/api/chat
Your API is ready to integrate with your frontend chatbot!