-
Notifications
You must be signed in to change notification settings - Fork 759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: listen EADDRINUSE: address already in use :::3000 #568
Comments
Could you send us the output of: |
Hi @rimiti I don't get any output |
UPDATE so the reason was because in my app.test.js file I had a series of tests that were not closing after completion because I was running tests like:
and I am still getting the error:
|
I had that exact error message, try this out: Expected: I can use app.listen(PORT, ()=>{}) Code: index.js exports "app", app.listen(PORT, ()=>{}) is uncommented Output: npm test => "Jest did not exit one second after the test run has completed. Workaround: comment/delete app.listen(PORT) and listen to the port on another file (example: require "app" from index.js in app.js and listen to a port in app.js) |
what's weird is that the documentation claims "if the server is not already listening for connections then it is bound to an ephemeral port for you so there is no need to keep track of ports." |
Ok thanks a lot, I will be checking that out for sure! |
Looks like you have to do two things:
request(app.callback()) |
|
You are actually running the main server in the terminal. Stop the server so the debugger can run on the same PORT |
So I had this issue as well. So modify your code so that when you're testing (for example by setting an environment variable and looking for that), you're not calling the listen() method. This should resolve it and let you run your tests in parallel. |
Cheers from brazil, thank you all for the support! |
What is PID here? New comer please help. Thank you. |
@HashemDeveloper when you run |
I actually figured that out by try and error. Thank you for the reply though. |
im new to web development and i get the same error and dont know exactly what to do can someone please dumb it down for me |
@Abdelrahmanyassin786 In your terminal window, where you are running your application; run this command: |
it tells me 1sof command is not found |
the thing is that my root route doesnt work but if i type for example /blog/new it opens fine |
@Abdelrahmanyassin786 It is not a number one it's the letter L |
still doesnt work |
i tried sth i typed killall -9 |
@spock123 please do you mean exporting the what i assign the express function to? const port = process.env.PORT || 3000; module.exports = server; Please do you mean i should export just app?? |
i experience these problem my solution to these: i restart my computer and run again then i find it running good again. but my problem (how to kill the server with out restarting it) |
Sometimes, when i press save and the server restarts i get the same error. |
I have the same problem and i couldn't understand what do @spock123 and @aech12 mean by exporting the server. |
Yes! precisely! |
Hi @zfnori This means you can export that "server" object like any other variable. |
Sure thing. Thanks a lot
…On Tue, Jun 30, 2020, 11:04 PM Lars Rye Jeppesen ***@***.***> wrote:
module.exports = server;
Please do you mean i should export just app??
Yes! precisely!
You export just the app, but do not call listen()
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#568 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJT3CM3LIBKK2KGQIEBUD73RZJVPNANCNFSM4HBWRWDQ>
.
|
thankyou @aech12 your solution work for me |
I have the same issue, solution that I found is go to node_modules find nodemon/monitor/run. And there is variable "killedAfterChange" in my case |
Hi everyon. I had this error: |
I added an additional node and started the server on it and ran with out issues. I am guessing you cant run concurrently dev dependencies on the main node. Not sure why this worked but basically just click the plus sign on your vs code in the terminal to open a secondary node and run the app. |
Never mind that didn't hold up after rerunning the app. I found that my insomnia running on the same port as my app is conflicting as I check my routes |
simple yet very effective answer. |
I had the same problem and instead of writing |
this is solution; tanks. |
This worked for me. Thanks a lot. |
I had the same problem and the problem was that I wrote app.listen() two times )))) |
Perhaps you have 2 projects and one with docker. Check "docker ps" - maybe you use this port. Then stop it. |
I had the same problem and just restart VS Code and the problem solved |
To fix this you need to avoid calling
In summary, one solution is to wrap if (process.env.NODE_ENV !== 'test') {
app.listen(port)
} And another solution is to organize your code so that |
For anyone whos struggling with koa , vitest and supertest , After doing what @AlbertVilaCalvo said in his comment, you will need to also init supertest passing app.callback() like this:
btw , no need to use afterEach, afterAll and so on to stop server |
Guys this none-sense took me about 2 days. I re-structured the code, because i had that double calling problem with the "app.listen()" method. I though that was finally it, but still no resolve. The problem is that I had test suites. And they run dynamically altogether. At some point during execution 2 different tests try to use the same port and BOOM, we got this error. Because you see, mostly the error appeared (EADDRINUSE), but sometimes it did not (I ran "npm test" like hundreds of times xD), so I couldnt wrap my head around it. So the solution is to change that default behaviour, to run test-suites SEQUENTIALLY, NOT in PARALLEL. So I just had to put "--runInBand" in scripts.jest : "scripts": { I also have other stuff in this "scripts. jest" object and "scripts.test", which I copied from all the potencial solutions in Stackoverflow and here Github. They didnt help, but I will just let them be. What solved my problem was purely "--runInBand". |
I just figured a solution for windows.
|
"scripts": { that's work with me |
After couple of tries, i found i put a semicolon " ; " at the end of variable value in the .env file.. just remove the semicolon.. and it will work |
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:
my router:
finally the test:
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
The text was updated successfully, but these errors were encountered: