I made a new node project with npm init.
When I enter command
➜ nodemon index.js
I got Error
[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
node:events:346
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3003
at Server.setupListenHandle [as _listen2] (node:net:1311:16)
at listenInCluster (node:net:1359:12)
at Server.listen (node:net:1446:7)
at Object.<anonymous> (/media/keval/New Volume1/👨💻️ KEVAL ACTIVITY/😎️ Skills/💻️ Programming/Builds/JavaScript/React-Native/Zoom/zoom-clone-api/index.js:12:8)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1338:8)
at processTicksAndRejections (node:internal/process/task_queues:81:21) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '::',
port: 3003
}
[nodemon] app crashed - waiting for file changes before starting..
and I am using LINUX(UBUNTU) so how can I avoid this.
and thankyou in advance for helping me.
One way of doing it is to running pkill -f nodemon
and then restart the server
You could also apply a delay to your nodemon
instance as such :
nodemon --delay 500ms index.js
This link sums up the rest for you :
You should also add :
process.once('SIGUSR2', function () {
process.kill(process.pid, 'SIGUSR2');
});
process.on('SIGINT', function () {
// this is only called on ctrl+c, not restart
process.kill(process.pid, 'SIGINT');
});