Reputation:
im getting the following error issue throw er; // Unhandled 'error' event
Here is my Controler.js
const router = require('express').Router();
router.post('/api/sendMail', async (req,res) => {
console.log("yes")
});
module.exports = router;
Here is my index.js
const cont = require('./controllers/Controler');
app.use(cont);
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::5000
at Server.setupListenHandle [as _listen2] (net.js:1286:14)
at listenInCluster (net.js:1334:12)
at Server.listen (net.js:1421:7)
at Function.listen (/Users/user/folder/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/Users/user/folder/server.js:24:5)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
Emitted 'error' event at:
at emitErrorNT (net.js:1313:8)
at process._tickCallback (internal/process/next_tick.js:63:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:744:11)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
Im not sure what im missing but im gettng unhandled error isssue.
Upvotes: 2
Views: 372
Reputation: 674
Try running your app using a different port or kill the process in the current port 5000
To kill a task in windows
//get process running in port 5000
netstat -ano | findstr :5000
//enter your pid and force kill
//replace <pID> with your process id
taskkill /PID <pID> /F
Upvotes: 0
Reputation: 44087
Use try/catch:
try {
app.use(cont);
} catch(er) {
console.log(er);
}
Also note that port 5000
is already in use (EADDRINUSE
) - try changing your port to something else.
Upvotes: 0
Reputation: 801
It seems like something already uses 5000 port.
If you use *nix based OS, you can get list of processes like this:
netstat -tulpn | grep 5000
and then, kill particular process:
kill -9 PID
Upvotes: 2