Error: Listen EADDRINUSE: address already in use ::3001

Asked

Viewed 1,924 times

-1

I can’t find the error in the code,

const express = require('express');
const mongoose = require('mongoose');

// Iniciando o App
const app = express();

// Iniciando o DB
mongoose.connect(
    'mongodb://localhost:27017/nodeapi',
    { useNewUrlParser: true }
);

// Primeira rota
app.get('/',(req, res)=>{
    res.send("Hello World");
});

app.listen(3001);

Someone could help me, because this error shows all the time in the execution of the code:

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::3001
    at Server.setupListenHandle [as _listen2] (net.js:1313:16)
    at listenInCluster (net.js:1361:12)
    at Server.listen (net.js:1447:7)
    at Function.listen (/var/www/html/NodeJS/node_modules/express/lib/application.js:618:24)
    at Object.<anonymous> (/var/www/html/NodeJS/server.js:18:5)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1340:8)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  code: 'EADDRINUSE',
  errno: 'EADDRINUSE',
  syscall: 'listen',
  address: '::',
  port: 3001
}
[nodemon] app crashed - waiting for file changes before starting...

how do I tidy up.

  • 2

    If I’m not mistaken, that mistake means something’s using your door 3001, it may be that you are running this script for the 2nd time and did not "kill" what you ran before.

  • nothing but the script.

  • 1

    Could you try another door? For example: app.listen(3003) or app.listen(3010) and tell the result?

  • now appears this message :(node:18136) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

1 answer

0


Hear that mistake:

(node:18136) DeprecationWarning: current Server Discovery and Monitoring
  engine is deprecated, and will be removed in a future version. To use
  the new Server Discover and Monitoring engine, pass option 
  { useUnifiedTopology: true } to the MongoClient constructor.

After changes in code like app.listen(3001) for app.listen(3003) and

mongoose.connect('mondodb://localhost:27017/nodeapi',{ useNewUrlParser: true });

for

mongoose.connect('mongodb://localhost:27017/nodeapi',{ useNewUrlParser: true });

in this error found the solution in this poust Server Discovery And Monitoring engine is deprecated,
which is basically adding one more term :

useNewUrlParser: true, useUnifiedTopology: true

Inside the keys: mongodb://localhost:27017/nodeapi', {});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.