question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: listen EADDRINUSE: address already in use :::3000

See original GitHub issue

Hey 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:42 (1 by maintainers)

github_iconTop GitHub Comments

193reactions
dionisoroscommented, Nov 5, 2019
lsof -i:3000 
kill -9 [PID] 
47reactions
rimiticommented, Mar 27, 2019

Could you send us the output of: lsof -i:3000

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found