debugbashModeratepending
Debug: macOS port already in use
Viewed 0 times
portEADDRINUSElsofkillprocessbind
Error Messages
Problem
Cannot start server because port is already in use. Need to find and kill the process using the port.
Solution
Find and kill the process using the port:
# Find process on port (macOS):
lsof -i :3000
lsof -i :3000 -t # Just the PID
# Kill it:
kill $(lsof -i :3000 -t)
kill -9 $(lsof -i :3000 -t) # Force kill
# Linux alternative:
fuser 3000/tcp
fuser -k 3000/tcp # Kill directly
# Common culprits on macOS:
# - AirPlay Receiver uses port 5000 (disable in System Settings > General > AirDrop & Handoff)
# - ControlCenter uses port 7000
# - Previous Node.js process that didnt clean up
# Prevent in Node.js:
process.on('SIGTERM', () => {
server.close(() => process.exit(0));
});
process.on('SIGINT', () => {
server.close(() => process.exit(0));
});
# Use a random available port:
const server = app.listen(0); // OS assigns available port
const port = server.address().port;
# Find process on port (macOS):
lsof -i :3000
lsof -i :3000 -t # Just the PID
# Kill it:
kill $(lsof -i :3000 -t)
kill -9 $(lsof -i :3000 -t) # Force kill
# Linux alternative:
fuser 3000/tcp
fuser -k 3000/tcp # Kill directly
# Common culprits on macOS:
# - AirPlay Receiver uses port 5000 (disable in System Settings > General > AirDrop & Handoff)
# - ControlCenter uses port 7000
# - Previous Node.js process that didnt clean up
# Prevent in Node.js:
process.on('SIGTERM', () => {
server.close(() => process.exit(0));
});
process.on('SIGINT', () => {
server.close(() => process.exit(0));
});
# Use a random available port:
const server = app.listen(0); // OS assigns available port
const port = server.address().port;
Revisions (0)
No revisions yet.