localhost:3001
Port 3001 is commonly used as a secondary development server when port 3000 is already occupied. It's popular for running backend APIs alongside frontend servers, microservices, or multiple projects simultaneously.
Open dev server:
http://localhost:3001
Common: Backend API | Second React app | Microservices
Common Uses for Port 3001
| Scenario | Port 3000 | Port 3001 |
|---|---|---|
| Full Stack App | React Frontend | Express/Node API |
| Microservices | Auth Service | User Service |
| Testing | Production Build | Dev Server |
| Multiple Projects | Project A | Project B |
Start Server on Port 3001
React (Create React App)
# Mac/Linux
PORT=3001 npm start
# Windows CMD
set PORT=3001 && npm start
# Windows PowerShell
$env:PORT=3001; npm start
# Or add to .env file
PORT=3001
Node.js / Express
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3001;
app.get('/api', (req, res) => {
res.json({ message: 'API running on port 3001' });
});
app.listen(PORT, () => {
console.log(`Server: http://localhost:${PORT}`);
});
Next.js
npx next dev -p 3001
# or
npm run dev -- -p 3001
Frontend-Backend Proxy Setup
When React runs on 3000 and API on 3001:
// package.json (React app)
{
"proxy": "http://localhost:3001"
}
// Now fetch('/api/users') automatically
// proxies to http://localhost:3001/api/users
CORS Configuration
// Express backend on 3001
const cors = require('cors');
app.use(cors({
origin: 'http://localhost:3000',
credentials: true
}));
Check What's Using Port 3001
# Mac/Linux
lsof -i :3001
# Windows
netstat -ano | findstr :3001
# Kill process
# Mac/Linux: kill -9 PID
# Windows: taskkill /F /PID PID
Troubleshooting
| Problem | Solution |
|---|---|
| Port already in use | Kill existing process or use 3002 |
| CORS errors | Add CORS middleware or use proxy |
| Connection refused | Check if server is actually running |
| API not responding | Verify correct port in fetch/axios calls |