-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.
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.– Icaro Martins
nothing but the script.
– miguel sr-robo
Could you try another door? For example:
app.listen(3003)
orapp.listen(3010)
and tell the result?– Danizavtz
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.
– miguel sr-robo