The Error Message
When you start a Node.js server and see this error, it means another process is already listening on that port:
Error: listen EADDRINUSE: address already in use :::3000
Or in Express:
Error: listen EADDRINUSE: address already in use 0.0.0.0:3000
Or in Next.js:
Port 3000 is already in use.
Use `next dev --port 3001` to use a different port.
The most common reason: a previous instance of your server is still running in the background, either in another terminal tab or because it crashed without releasing the port.
One-Command Fix with portrm
The fastest way to fix this in any Node.js project:
$ ptrm fix 3000 -y
Port 3000 in use
Node.js (PID 42891) - Express server
SAFE - dev server
Killed PID 42891
Port 3000 is now free
Or fix and restart in one step:
$ ptrm fix 3000 --run "npm run dev"
Install: npm install -g portrm or try instantly with npx portrm fix 3000
Fix for Express
Express apps typically listen on port 3000. When the port is taken:
$ ptrm fix 3000 --run "node app.js"
Or manually:
$ lsof -ti :3000 | xargs kill -9
$ node app.js
To use a different port in Express:
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server on port ${PORT}`));
Then: PORT=3001 node app.js
Fix for Next.js
Next.js defaults to port 3000 and shows a helpful message when it is taken:
$ ptrm fix 3000 --run "npx next dev"
Or change the port:
$ npx next dev --port 3001
Fix for Vite / React
Vite defaults to port 5173. If that is taken:
$ ptrm fix 5173 --run "npm run dev"
Vite usually auto-increments to the next available port, but if you need a specific port, add to vite.config.js:
export default defineConfig({
server: { port: 3000, strictPort: true }
})
Change the Default Port
| Framework | Default Port | How to Change |
|---|---|---|
| Express | 3000 | PORT=3001 node app.js |
| Next.js | 3000 | next dev -p 3001 |
| Vite | 5173 | vite --port 3001 |
| Create React App | 3000 | PORT=3001 npm start |
| Fastify | 3000 | fastify.listen({ port: 3001 }) |
| NestJS | 3000 | app.listen(3001) |
Prevent the Error Programmatically
Add graceful shutdown to your Node.js application so it releases the port when it exits:
const server = app.listen(3000);
process.on('SIGTERM', () => {
server.close(() => process.exit(0));
});
process.on('SIGINT', () => {
server.close(() => process.exit(0));
});
Or use portrm to manage your dev stack and handle this automatically:
$ ptrm init # create .ptrm.toml
$ ptrm up # start all services with graceful management
$ ptrm watch 3000 # auto-restart on crash
Stop fighting port conflicts in Node.js
portrm detects Node.js services automatically and handles graceful shutdown.