Node.js/Express backend for Voxa real-time translation app, deployable on Render.com.
- ✅ Translation API (Gemini 2.5 Pro)
- ✅ Text-to-Speech API (Gemini 2.5 Pro Preview TTS)
- ✅ Command parsing
- ✅ Request caching (10-minute TTL)
- ✅ Rate limiting (60 req/min)
- ✅ API key authentication
- ✅ CORS support
- ✅ Compression
- ✅ Health checks
cd backend
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Edit .env and add your Gemini API key
nano .env
# Start development server
npm run devServer will run on http://localhost:3000
# Health check
curl http://localhost:3000/health
# Translation (with API key)
curl -X POST http://localhost:3000/api/translate \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your_api_secret" \
  -d '{
    "text": "Hello, how are you?",
    "sourceLanguage": "en",
    "targetLanguage": "ko",
    "tone": "neutral"
  }'
# TTS
curl -X POST http://localhost:3000/api/tts \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your_api_secret" \
  -d '{
    "text": "안녕하세요",
    "languageCode": "ko-KR"
  }'
# Command parsing
curl -X POST http://localhost:3000/api/command \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer your_api_secret" \
  -d '{
    "command": "switch to Japanese"
  }'# Initialize git (if not already done)
cd backend
git init
git add .
git commit -m "Initial backend commit"
# Push to GitHub
gh repo create voxa-backend --public --source=. --remote=origin --push- 
Go to render.com and sign in 
- 
Click "New +" → "Web Service" 
- 
Connect your GitHub repository 
- 
Select voxa-backendrepo
- 
Configure: - Name: voxa-backend
- Region: Oregon (or closest to you)
- Branch: main
- Root Directory: Leave empty (or backendif it's in a subdirectory)
- Environment: Node
- Build Command: npm install
- Start Command: npm start
- Plan: Free
 
- 
Add Environment Variables: - GEMINI_API_KEY: Your Gemini API key
- API_SECRET: Generate a random secret (or let Render auto-generate)
- NODE_ENV: production
- RATE_LIMIT: 60
- ALLOWED_ORIGINS: * (or your app domains)
 
- 
Click "Create Web Service" 
Once deployed, Render will provide a URL like:
https://voxa-backend.onrender.com
Use this URL in your iOS app!
Translate text between languages.
Request:
{
  "text": "Hello, how are you?",
  "sourceLanguage": "en",
  "targetLanguage": "ko",
  "tone": "neutral",
  "preserveNames": true
}Response:
{
  "translation": "안녕하세요, 어떻게 지내세요?",
  "cached": false,
  "sourceLanguage": "en",
  "targetLanguage": "ko",
  "tone": "neutral"
}Tone Options:
- casual: Conversational
- neutral: Professional (default)
- business_formal: Formal business
Batch translate multiple texts (max 10).
Request:
{
  "texts": ["Hello", "Goodbye", "Thank you"],
  "sourceLanguage": "en",
  "targetLanguage": "ko",
  "tone": "neutral"
}Response:
{
  "translations": [
    { "original": "Hello", "translation": "안녕하세요", "cached": false },
    { "original": "Goodbye", "translation": "안녕히 가세요", "cached": false },
    { "original": "Thank you", "translation": "감사합니다", "cached": false }
  ]
}Generate speech from text.
Request:
{
  "text": "Hello, how are you?",
  "languageCode": "en-US",
  "voiceName": "Puck"
}Response:
{
  "audio": "base64_encoded_mp3_data",
  "mimeType": "audio/mpeg",
  "cached": false
}Voice Names:
- Puck: Natural, conversational
- Charon: Deep, authoritative
- Kore: Soft, pleasant
- Fenrir: Energetic
- Aoede: Warm, expressive
List available voices.
Response:
{
  "voices": [
    { "name": "Puck", "language": "en", "characteristics": "Natural, conversational" },
    { "name": "Charon", "language": "en", "characteristics": "Deep, authoritative" }
  ]
}Parse voice command.
Request:
{
  "command": "switch to Japanese"
}Response:
{
  "intent": "switch_language",
  "parameters": { "language": "ja" },
  "confidence": 0.95
}Supported Intents:
- switch_language
- set_mode
- pause/- resume
- repeat
- explain
- summarize
Health check endpoint.
Response:
{
  "status": "ok",
  "timestamp": "2025-10-21T10:30:00.000Z",
  "uptime": 12345
}All /api/* endpoints require authentication:
Authorization: Bearer YOUR_API_SECRETSet API_SECRET in environment variables.
- 60 requests per minute per IP (configurable)
- Returns 429 Too Many Requestswhen exceeded
- Translation results cached for 10 minutes
- TTS audio cached for 10 minutes
- Cache key includes all parameters
- Cached responses include "cached": true
All errors return JSON:
{
  "error": "Error message",
  "details": "Additional details",
  "timestamp": "2025-10-21T10:30:00.000Z"
}Common Status Codes:
- 400: Bad request (missing parameters)
- 401: Unauthorized (invalid API key)
- 429: Rate limit exceeded
- 500: Server error
View logs on Render dashboard or via CLI:
# Install Render CLI
npm install -g render-cli
# View logs
render logs -s voxa-backendMonitor on Render dashboard:
- CPU usage
- Memory usage
- Request count
- Response times
- Error rates
- Enable Caching: Results are cached automatically
- Use Batch Endpoints: For multiple translations
- Compress Responses: Enabled by default (gzip)
- Connection Pooling: Axios handles this
- Keep-Alive: Enabled by default
- Translation: ~1-2 seconds
- TTS: ~2-4 seconds
- Command parsing: ~0.5-1 second
- Cached responses: <100ms
- API Secret: Use strong, random secret
- CORS: Set specific allowed origins in production
- Rate Limiting: Adjust based on your needs
- HTTPS: Render provides free SSL
- Environment Variables: Never commit .envfile
-  Set strong API_SECRET
-  Configure ALLOWED_ORIGINS(not*)
- Enable rate limiting
- Set up monitoring alerts
- Configure logging
- Test error handling
- Memory: 512 MB
- Instances: 1
- Sleep: After 15 minutes of inactivity
- Bandwidth: Unlimited
For production:
- 
Starter Plan ($7/month): - No sleep
- 512 MB RAM
- Always on
 
- 
Standard Plan ($25/month): - 2 GB RAM
- Horizontal scaling
- Priority support
 
Check:
- Environment variables are set
- GEMINI_API_KEYis valid
- Port is not in use locally
- Dependencies installed (npm install)
Check:
- Text length (<5000 chars)
- Gemini API key has TTS access
- Internet connection
- Rate limits not exceeded
Solutions:
- Enable caching (already enabled)
- Use batch endpoints
- Deploy to region closer to users
- Upgrade Render plan
backend/
├── server.js           # Main server
├── routes/
│   ├── translation.js  # Translation endpoints
│   ├── tts.js          # TTS endpoints
│   └── command.js      # Command parsing
├── package.json        # Dependencies
├── .env.example        # Environment template
├── render.yaml         # Render config
└── README.md           # This file
- Create route file in routes/
- Import in server.js
- Add middleware and validation
- Update documentation
# Run tests (when implemented)
npm test
# Manual testing
npm run dev
# Use Postman or curl for API testingFor issues:
- Check logs on Render dashboard
- Review Render docs
- Check Gemini API status
- Review this README
MIT
Last Updated: October 21, 2025