This guide covers setting up RefactorAI for local development with hot reloading and real-time code changes.
- Backend automatically restarts when you change server code
- Watches for changes in
src/,server.js, and even frontend files - No need to manually restart the server
- Code editor on the left is now fully scrollable
- Handles long code files gracefully
- Custom scrollbar styling for better UX
- Responsive design for different screen sizes
- Node.js installed
- Google AI API key
- Git repository cloned locally
- Backend Environment (
backend/.env):
GOOGLE_API_KEY=your_google_ai_api_key_here
PORT=3000
NODE_ENV=development- Frontend Environment (
frontend/.env- optional for separate dev):
VITE_API_BASE_URL=http://localhost:3000This approach serves the built frontend from the backend with hot reload:
# 1. Build the frontend first
node build.js
# 2. Start backend with nodemon (will auto-restart on changes)
cd backend && npm run devBenefits:
- β Single service (same as production)
- β Backend hot reload on code changes
- β No CORS issues
- β Need to rebuild frontend for frontend changes
This runs frontend and backend separately with full hot reload:
# Terminal 1: Backend with nodemon
cd backend && npm run dev
# Terminal 2: Frontend with Vite dev server
cd frontend && npm run devBenefits:
- β Full hot reload for both frontend and backend
- β Instant frontend updates
- β Need to handle CORS
- β Different setup than production
Test the production build locally:
# Build and start (no hot reload)
node build.js
cd backend && npm startnpm start # Start server (production mode)
npm run dev # Start with nodemon (hot reload)
npm run dev:watch # Advanced watching (includes frontend)
npm run build # Build frontend from backend
npm test # Run testsnpm run dev # Vite dev server with hot reload
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Lint codeThe backend includes nodemon.json with optimized settings:
{
"watch": ["src", "server.js", "../frontend/src"],
"ext": "js,json,jsx,css",
"ignore": ["node_modules", "dist", "build"],
"delay": 1000,
"verbose": true
}What it does:
- Watches backend
src/folder andserver.js - Optionally watches frontend
src/for full-stack development - Ignores
node_modulesand build folders - 1-second delay to avoid multiple restarts
- Verbose logging to see what triggered restarts
- Vertical Scroll: Long code files scroll vertically
- Horizontal Scroll: Long lines scroll horizontally
- Resizable: Can resize the editor vertically with
resize: vertical - Custom Scrollbars: Styled scrollbars for better appearance
- Font: Fira Code/Fira Mono monospace
- Theme: Dark theme matching the overall design
- Syntax Highlighting: JavaScript syntax highlighting via Prism.js
- Responsive: Adapts to different screen sizes
- Use Option 1 for backend-focused development
- Use Option 2 when actively working on frontend
- Use Option 3 to test production builds
- Check Terminal: Nodemon shows restart reasons
- Browser DevTools: Check Network tab for API calls
- API Testing: Test endpoints directly at
http://localhost:3000/ai/get-review
- Backend Changes: Auto-reload with nodemon
- Frontend Changes:
- Option 1: Need to rebuild (
npm run build) - Option 2: Instant reload with Vite
- Option 1: Need to rebuild (
- "vite: not found": Run
npm install --include=devin frontend - Port conflicts: Change PORT in backend
.env - CORS errors: Use same origin or configure CORS properly
- Nodemon not restarting: Check
nodemon.jsonwatch patterns
# Make a change to src/app.js or src/controllers/ai.controller.js
# Nodemon should automatically restart
# Check terminal for restart logsOption 1 (Full-stack):
cd frontend && npm run build
# Backend will serve new frontendOption 2 (Separate dev):
# Changes automatically reload in browser- Paste a long code file (100+ lines)
- Verify vertical scrolling works
- Add long lines and verify horizontal scrolling
- Test on mobile/tablet (responsive design)
When ready to deploy, the development setup seamlessly transitions to production:
# Same commands work for deployment
node build.js
cd backend && npm startThe production build uses the same architecture as Option 1 development mode.