6.0 KiB
6.0 KiB
Node.js Multi-User Transcription Server
Much better than PHP for real-time applications!
Why Node.js is Better Than PHP for This
- Native WebSocket Support - No SSE buffering issues
- Event-Driven - Designed for real-time connections
- No Buffering Problems - PHP-FPM/FastCGI buffering is a nightmare
- Lower Latency - Instant message delivery
- Better Resource Usage - One process handles all connections
- Easy to Deploy - Works on any VPS, cloud platform, or even Heroku free tier
Quick Start
Installation
cd server/nodejs
npm install
Run the Server
# Production
npm start
# Development (auto-restart on changes)
npm run dev
The server will start on port 3000 by default.
Change Port
PORT=8080 npm start
Usage
For Desktop App Users
- Open Local Transcription app
- Go to Settings → Server Sync
- Enable "Server Sync"
- Enter:
- Server URL:
http://your-server.com:3000/api/send - Room Name: Your room (e.g., "my-stream-123")
- Passphrase: Shared secret (e.g., "mysecretpass")
- Server URL:
For OBS Browser Source
Add a Browser source with this URL:
http://your-server.com:3000/display?room=YOUR_ROOM&fade=10×tamps=true
Parameters:
room- Your room name (required)fade- Seconds before text fades (0 = never fade)timestamps- Show timestamps (true/false)
API Endpoints
Send Transcription
POST /api/send
Content-Type: application/json
{
"room": "my-room",
"passphrase": "my-secret",
"user_name": "Alice",
"text": "Hello everyone!",
"timestamp": "12:34:56"
}
List Transcriptions
GET /api/list?room=my-room
WebSocket Connection
const ws = new WebSocket('ws://localhost:3000/ws?room=my-room');
ws.onmessage = (event) => {
const transcription = JSON.parse(event.data);
console.log(transcription);
};
Deployment Options
Option 1: VPS (DigitalOcean, Linode, etc.)
# SSH into your server
ssh user@your-server.com
# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
# Clone/upload your code
cd /opt
git clone <your-repo>
cd local-transcription/server/nodejs
# Install dependencies
npm install --production
# Install PM2 (process manager)
sudo npm install -g pm2
# Start server with PM2
pm2 start server.js --name transcription-server
# Make it start on boot
pm2 startup
pm2 save
# Check status
pm2 status
Option 2: Docker
Create Dockerfile:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
Run:
docker build -t transcription-server .
docker run -p 3000:3000 -v ./data:/app/data transcription-server
Option 3: Heroku (Free Tier)
# Install Heroku CLI
curl https://cli-assets.heroku.com/install.sh | sh
# Login
heroku login
# Create app
cd server/nodejs
heroku create my-transcription-server
# Deploy
git init
git add .
git commit -m "Initial commit"
git push heroku main
# Your URL will be: https://my-transcription-server.herokuapp.com
Option 4: Railway.app (Free Tier)
- Go to https://railway.app
- Connect your GitHub repo
- Select the
server/nodejsdirectory - Deploy automatically
- Railway will provide a URL
Option 5: Local Network (LAN Party, etc.)
# Run on your local machine
npm start
# Find your local IP
# Linux/Mac: ifconfig | grep "inet "
# Windows: ipconfig
# Others connect to: http://YOUR_LOCAL_IP:3000
Reverse Proxy (Nginx)
If you want to use port 80/443 with SSL:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
For SSL (Let's Encrypt):
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com
Environment Variables
PORT=3000 # Server port (default: 3000)
DATA_DIR=/path/to/data # Data directory (default: ./data)
Monitoring
With PM2:
pm2 logs transcription-server # View logs
pm2 monit # Monitor resources
pm2 restart transcription-server # Restart
Check if running:
curl http://localhost:3000/
Troubleshooting
Port already in use
# Find process using port 3000
lsof -i :3000
# Or on Linux:
sudo netstat -tlnp | grep 3000
# Kill it
kill -9 <PID>
Permission denied on port 80
Ports below 1024 require root. Either:
- Use port 3000+ and reverse proxy with Nginx
- Or run with sudo (not recommended)
WebSocket connection fails
- Check firewall allows port 3000
- Verify server is running:
curl http://your-server:3000 - Check browser console for errors
Data not persisting
- Ensure
data/directory is writable - Check disk space
- Verify PM2 is running:
pm2 status
Security Recommendations
- Use HTTPS in production - Set up Let's Encrypt with Nginx
- Firewall - Only allow necessary ports
- Rate Limiting - Add express-rate-limit if public
- Strong Passphrases - Use long, random passphrases for rooms
- Regular Updates - Keep Node.js and dependencies updated
Performance
Tested with:
- 50 concurrent WebSocket connections
- 10 transcriptions/second
- Average latency: < 100ms
- Memory usage: ~50MB
Comparison: Node.js vs PHP
| Feature | Node.js | PHP (SSE) |
|---|---|---|
| Real-time | ✅ WebSocket | ⚠️ SSE (buffering issues) |
| Latency | < 100ms | 1-5 seconds (buffering) |
| Connections | 1000+ | Limited by PHP-FPM |
| Setup | Easy | Complex (Apache/Nginx config) |
| Hosting | VPS, Cloud | Shared hosting (problematic) |
| Resource Usage | Low | High (one PHP process per connection) |
License
Part of the Local Transcription project.