Express.js backend that generates AI-powered motivational quotes using Google Gemini API.
-
Install dependencies:
npm install
-
Create
.envfile:cp .env.example .env
-
Get Gemini API Key:
- Visit: https://makersuite.google.com/app/apikey
- Create a new API key
- Add it to your
.envfile:GEMINI_API_KEY=your_actual_api_key_here
-
Run the server:
npm start
For development with auto-reload:
npm run dev
Endpoint: POST /api/quote
Request Body:
{
"totalHabits": 5,
"completedYesterday": 3,
"bestStreak": 12,
"bestStreakHabitName": "Reading",
"averageStreak": 5
}Response:
{
"quote": "Your Reading streak is unstoppable! 12 days of growth - keep shining!"
}Endpoint: GET /health
Response:
{
"status": "ok",
"message": "Habit Tracker Quote API is running"
}Use the special IP address that maps to your computer's localhost:
http://10.0.2.2:3000/api/quote
Use your computer's local IP address:
http://192.168.x.x:3000/api/quote
To find your local IP:
- Linux/Mac:
ifconfigorip addr - Windows:
ipconfig
This backend can be deployed to:
- Vercel (recommended for Express apps)
- Railway
- Render
- Heroku
- DigitalOcean App Platform
Remember to set the GEMINI_API_KEY environment variable in your deployment platform.
curl -X POST http://localhost:3000/api/quote \
-H "Content-Type: application/json" \
-d '{
"totalHabits": 5,
"completedYesterday": 3,
"bestStreak": 12,
"bestStreakHabitName": "Reading",
"averageStreak": 5
}'