Error: listen EADDRINUSE: address already in use :::3000
See original GitHub issueHey guys, so I have been just trying to start testing my Koa server using Supertest.
I am getting the error: Error: listen EADDRINUSE: address already in use :::3000
I have tried closing everything down on that port and run it but I’m still getting the issue.
Here is my app:
require('dotenv').config();
const Koa = require('koa');
const app = new Koa();
const router = require('./router');
const PORT = process.env.NODE_PORT || 3001;
const ENV = process.env.NODE_ENV || 'Development';
const logger = require('koa-logger');
app.use(logger());
app.use(router.routes());
app.listen(PORT, (err) => {
if (err) console.error('❌ Unable to connect the server: ', err);
console.log(`🌍 Server listening on port ${PORT} - ${ENV} environment`);
});
module.exports = app;
my router:
const Router = require('koa-router');
const router = new Router();
router.get('/', ctx => ctx.body = 'Sending some JSON');
module.exports = router;
finally the test:
const server = require('../index');
const request = require('supertest').agent(server.listen());
afterEach(() => {
server.close();
});
describe('routes: index', ()=> {
it('should reach endpoint', async () => {
const response = await request(server).get('/');
expect(response.status).toEqual(200);
expect(response.body).toEqual('Sending some JSON');
});
});
my server isn’t even running on port 3000 it is running on 8080 however, just to make sure I will run my server on 3000 and it starts up no problem. I then try to run the test, I get the error again with the server running on 3000 and the server not. Kinda stuck
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:42 (1 by maintainers)
Top Results From Across the Web
Node / Express: EADDRINUSE, Address already in use - Kill ...
First, you would want to know which process is using port 3000 sudo lsof -i :3000. this will list all PID listening on...
Read more >How to kill server when seeing “EADDRINUSE: address ...
Nodejs listen EADDRINUSE: address already in use. The Problem. When trying to restart a Node application, the previous one did not shut down ......
Read more >Error: listen EADDRINUSE: address already in use :::3000 #568
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with --detectOpenHandles to ...
Read more >How To Solve "EADDRINUSE - Address Already In Use"
Find the process ID. First things first, we need to identify the process ID of the application that's occupying the port. · Terminate...
Read more >Listen EADDRINUSE: address already in use :::3000 - Node
Hi guys, I'm stuck with this damn error, anyone solved this issue?, I'm confidence that the code 100% is the same as Mosh...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Could you send us the output of:
lsof -i:3000