Reputation: 3
Hey everyone i am new here, trying to follow along a course on Udemy about connecting Node app to database, but stuck on a problem can't actually run the server using MongoDB database. Code is at the end.
The error
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (net.js:1317:16)
at listenInCluster (net.js:1365:12)
at Server.listen (net.js:1451:7)
at Function.listen (C:\Users\Elev\Desktop\javapamokos\todolist\todolistonSteroids\node_modules\express\lib\application.js:618:24)
at C:\Users\Elev\Desktop\javapamokos\todolist\todolistonSteroids\server.js:10:5
at C:\Users\Elev\Desktop\javapamokos\todolist\todolistonSteroids\node_modules\mongodb\lib\utils.js:674:5
at C:\Users\Elev\Desktop\javapamokos\todolist\todolistonSteroids\node_modules\mongodb\lib\mongo_client.js:225:7
at connectCallback (C:\Users\Elev\Desktop\javapamokos\todolist\todolistonSteroids\node_modules\mongodb\lib\operations\connect.js:366:5)
at C:\Users\Elev\Desktop\javapamokos\todolist\todolistonSteroids\node_modules\mongodb\lib\operations\connect.js:602:5
at connectHandler (C:\Users\Elev\Desktop\javapamokos\todolist\todolistonSteroids\node_modules\mongodb\lib\core\sdam\topology.js:297:43)
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1344:8)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
code: 'EADDRINUSE',
errno: -4091,
syscall: 'listen',
address: '::',
port: 3000
}
code part 1 (https://prnt.sc/v8rnqm) code part 2 (https://prnt.sc/v8rofm)
Upvotes: 0
Views: 1360
Reputation: 2800
On line 10 you already calling app.listen(3000)
and then (lines are hidden by screenshot) in the bottom of the file you are calling app.listen(3000)
again. That's the reason, leave it on line 10 only. If you need this instance multiple times think about assigning it to a constant. For example:
const socket_id = app.listen(3000)
Upvotes: 1