localhost:3001
http://localhost:3001
Port 3001 is commonly used as an alternative development port when port 3000 is already occupied. It's the default fallback for React, Node.js, Express, and other JavaScript frameworks when running multiple development servers simultaneously.
→ Open localhost:3001
When to Use Port 3001
- Port 3000 already in use - Another dev server is running
- Multiple Node.js applications - Running frontend and backend separately
- Backend API on separate port - Frontend on 3000, API on 3001
- Microservices architecture - Different services on different ports
- Multiple React projects - Testing different apps simultaneously
- Full-stack development - Separate client and server ports
- Testing environments - Production-like setup with multiple services
Start Servers on Port 3001
React on Port 3001
# Windows
set PORT=3001 && npm start
# Windows PowerShell
$env:PORT=3001; npm start
# Linux/Mac
PORT=3001 npm start
# Cross-platform with cross-env
npx cross-env PORT=3001 npm start
# Access at: http://localhost:3001
Express.js on Port 3001
// server.js
const express = require('express');
const app = express();
const PORT = 3001;
app.get('/', (req, res) => {
res.json({
message: 'Backend API running on port 3001',
port: PORT
});
});
app.get('/api/users', (req, res) => {
res.json([
{ id: 1, name: 'John Doe' },
{ id: 2, name: 'Jane Smith' }
]);
});
app.listen(PORT, () => {
console.log(`API server running on http://localhost:${PORT}`);
});
// Run: node server.js
Next.js on Port 3001
# Start Next.js on port 3001
npm run dev -- -p 3001
# Or set in package.json
{
"scripts": {
"dev": "next dev -p 3001"
}
}
# Access at: http://localhost:3001
Node.js HTTP Server on Port 3001
// server.js
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify({
message: 'Server running on port 3001',
timestamp: new Date().toISOString()
}));
});
server.listen(3001, () => {
console.log('Server listening on http://localhost:3001');
});
Common Use Case: Frontend on 3000, Backend on 3001
This is the standard setup for full-stack JavaScript development:
Backend API (Port 3001)
// backend/server.js
const express = require('express');
const cors = require('cors');
const app = express();
// Enable CORS for frontend on port 3000
app.use(cors({
origin: 'http://localhost:3000'
}));
app.use(express.json());
// API endpoints
app.get('/api/data', (req, res) => {
res.json({ message: 'Data from backend API' });
});
app.post('/api/submit', (req, res) => {
console.log('Received:', req.body);
res.json({ success: true, data: req.body });
});
app.listen(3001, () => {
console.log('Backend API running on http://localhost:3001');
});
// Run: node backend/server.js
Frontend React App (Port 3000)
// frontend/src/App.js
import { useState, useEffect } from 'react';
function App() {
const [data, setData] = useState(null);
useEffect(() => {
// Fetch from backend API on port 3001
fetch('http://localhost:3001/api/data')
.then(res => res.json())
.then(data => setData(data))
.catch(err => console.error(err));
}, []);
const handleSubmit = async (formData) => {
const response = await fetch('http://localhost:3001/api/submit', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData)
});
const result = await response.json();
console.log(result);
};
return <div>{data && <p>{data.message}</p>}
;
}
// Frontend runs on: http://localhost:3000
// Backend runs on: http://localhost:3001
Alternative: Use Proxy in React
// package.json in React app
{
"proxy": "http://localhost:3001"
}
// Now you can use relative URLs
fetch('/api/data') // Proxied to http://localhost:3001/api/data
.then(res => res.json())
.then(data => console.log(data));
// No need for CORS in backend
// No need to specify full URL in frontend
Run Multiple Development Servers
# Terminal 1 - Frontend on port 3000
cd frontend
npm start
# Terminal 2 - Backend API on port 3001
cd backend
PORT=3001 node server.js
# Terminal 3 - Admin panel on port 3002
cd admin
PORT=3002 npm start
# Terminal 4 - Mock API on port 3003
json-server --watch db.json --port 3003
# All services running simultaneously
# Frontend: http://localhost:3000
# Backend: http://localhost:3001
# Admin: http://localhost:3002
# Mock API: http://localhost:3003
Check if Port 3001 is in Use
# Windows
netstat -ano | findstr :3001
tasklist | findstr [PID]
# Linux/Mac
lsof -i :3001
sudo lsof -i :3001
netstat -an | grep 3001
# Check all Node processes
ps aux | grep node
# Windows - Check all Node processes
tasklist | findstr node.exe
Kill Process on Port 3001
# Windows
netstat -ano | findstr :3001
taskkill /PID [PID] /F
# Linux/Mac
lsof -ti:3001 | xargs kill -9
sudo lsof -ti:3001 | xargs kill -9
# Using npx kill-port
npx kill-port 3001
# Kill multiple ports at once
npx kill-port 3000 3001 3002
Configure React to Always Use Port 3001
Create .env File
# .env file in project root
PORT=3001
# React will automatically use this port
# Run: npm start
# Server starts at http://localhost:3001
Modify package.json
// package.json
{
"scripts": {
"start": "PORT=3001 react-scripts start",
"start:win": "set PORT=3001 && react-scripts start",
"start:cross": "cross-env PORT=3001 react-scripts start"
}
}
// Install cross-env for cross-platform support
npm install --save-dev cross-env
CORS Configuration for Port 3001 Backend
// server.js - Allow requests from frontend on port 3000
const express = require('express');
const cors = require('cors');
const app = express();
// Option 1: Allow specific origin
app.use(cors({
origin: 'http://localhost:3000',
credentials: true
}));
// Option 2: Allow multiple origins
app.use(cors({
origin: ['http://localhost:3000', 'http://localhost:3002'],
credentials: true
}));
// Option 3: Allow all origins (development only)
app.use(cors());
// Option 4: Custom CORS configuration
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', 'http://localhost:3000');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.header('Access-Control-Allow-Credentials', 'true');
next();
});
app.listen(3001);
// Install CORS package
// npm install cors
Microservices on Sequential Ports
// Service 1 - User Service (Port 3001)
// users-service/server.js
const express = require('express');
const app = express();
app.get('/api/users', (req, res) => {
res.json([{ id: 1, name: 'User 1' }]);
});
app.listen(3001, () => console.log('Users service on 3001'));
// Service 2 - Products Service (Port 3002)
// products-service/server.js
const express = require('express');
const app = express();
app.get('/api/products', (req, res) => {
res.json([{ id: 1, name: 'Product 1' }]);
});
app.listen(3002, () => console.log('Products service on 3002'));
// Service 3 - Orders Service (Port 3003)
// orders-service/server.js
const express = require('express');
const app = express();
app.get('/api/orders', (req, res) => {
res.json([{ id: 1, total: 100 }]);
});
app.listen(3003, () => console.log('Orders service on 3003'));
// API Gateway on Port 3000 routing to all services
Environment-Specific Port Configuration
// config.js
const config = {
development: {
port: 3001,
apiUrl: 'http://localhost:3001'
},
staging: {
port: 8001,
apiUrl: 'https://staging-api.example.com'
},
production: {
port: 80,
apiUrl: 'https://api.example.com'
}
};
const env = process.env.NODE_ENV || 'development';
module.exports = config[env];
// server.js
const config = require('./config');
const express = require('express');
const app = express();
app.listen(config.port, () => {
console.log(`Server running on port ${config.port}`);
});
Docker Compose with Multiple Ports
# docker-compose.yml
version: '3.8'
services:
frontend:
build: ./frontend
ports:
- "3000:3000"
environment:
- REACT_APP_API_URL=http://localhost:3001
backend:
build: ./backend
ports:
- "3001:3001"
environment:
- DATABASE_URL=mongodb://db:27017/myapp
database:
image: mongo:latest
ports:
- "27017:27017"
# Run all services
# docker-compose up
# Access:
# Frontend: http://localhost:3000
# Backend API: http://localhost:3001
# Database: localhost:27017
Test Port 3001 Connection
# Test with curl
curl http://localhost:3001
# Test API endpoint
curl http://localhost:3001/api/users
# Test POST request
curl -X POST http://localhost:3001/api/data \
-H "Content-Type: application/json" \
-d '{"key":"value"}'
# Test with telnet
telnet localhost 3001
# Windows PowerShell
Test-NetConnection -ComputerName localhost -Port 3001
# Test from browser
# Open: http://localhost:3001
Nodemon for Auto-Restart on Port 3001
# Install nodemon globally
npm install -g nodemon
# Or as dev dependency
npm install --save-dev nodemon
# Run server with nodemon
nodemon server.js
# With specific port
PORT=3001 nodemon server.js
# package.json script
{
"scripts": {
"dev": "nodemon server.js",
"dev:3001": "PORT=3001 nodemon server.js"
}
}
# Run: npm run dev:3001
# Server auto-restarts when files change
Firewall Configuration for Port 3001
Windows Firewall
# Allow port 3001
netsh advfirewall firewall add rule name="Node Port 3001" dir=in action=allow protocol=TCP localport=3001
# Remove rule
netsh advfirewall firewall delete rule name="Node Port 3001"
Linux Firewall (UFW)
# Allow port 3001
sudo ufw allow 3001/tcp
# Check status
sudo ufw status
# Remove rule
sudo ufw delete allow 3001/tcp
Common Port 3001 Issues
CORS errors when accessing port 3001 from port 3000
- Backend not configured for CORS
- Install and configure cors package in Express
- Allow specific origins in CORS configuration
- Or use proxy in React package.json
Port 3001 connection refused
- Backend server not running
- Server crashed due to error
- Check server logs for errors
- Verify server is listening on correct port
- Firewall blocking connections
Cannot start server - port 3001 in use
- Another process using port 3001
- Previous server instance not killed properly
- Kill process on port 3001
- Use different port like 3002
Development Tip:
Using sequential ports (3000, 3001, 3002) makes it easy to remember which service runs on which port. Document your port assignments in project README for team consistency.
Frequently Asked Questions
Why use port 3001 instead of 3000?
Port 3001 is used when 3000 is occupied or when running multiple services. It's the natural next port and follows JavaScript ecosystem conventions.
Can I run frontend and backend on same port?
Not simultaneously. Each port can only have one server. Separate ports (3000 for frontend, 3001 for backend) is standard practice in development.
How do I connect React on 3000 to backend on 3001?
Either configure CORS in backend to allow requests from port 3000, or use proxy in React's package.json to forward API requests.
Do I need different ports in production?
No. In production, use reverse proxy (Nginx, Apache) to handle routing. Frontend and backend can both be on port 80/443 with different paths or domains.
What if port 3001 is also busy?
Use port 3002, 3003, or any available port. Node.js development has no strict port requirements beyond avoiding conflicts.
Related Ports and Resources