nodemon is crashing after several changes done in project files? - node.js

When I update the project Files I get this issue given Below:
events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::4000
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at Server.setupListenHandle [as _listen2] (net.js:1351:14)
at listenInCluster (net.js:1392:12)
at Server.listen (net.js:1476:7)
at Function.listen (E:\nodejs-mysql-authentication- master\node_modules\express\lib\application.js:618:24)
at Object.<anonymous> (E:\nodejs-mysql-authentication-master\server.js:26:5)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
[nodemon] app crashed - waiting for file changes before starting...
I already try all this point to short out this issue given below
1.I manually stops the all node services than again I try npm start It's not worked if i change port 4001 it's work after, some time again same issue port 4001.
2.I Increase the nodemon file watcher size but still this issue not get solved.
But When I restart My PC again then nodemon is working on same port.
So How I can solve this issue, If I don't want to change my port and can't restart my PC.

Adding --signal SIGTERM to nodemon command line fixed for me. You can have more details at nodemon project # github.com
The issue occurs due to a thread still running when nodemon restarts the app, and this thread is already using the port you want to use. You can confirm this with these steps:
Make nodemon crash. You should see something like the error posted by OP
hit CTRL+c when it happens to stop nodemon
enter netstat -napt | grep [YOUR_PORT], replace [YOUR_PORT] with the port number you are using. In the OP's case it's 4000
you should get the process listening on that port. The command will return something like this:
ff#darkpc:~/dev/dp/graphql/teste1> netstat -napt | grep 4000
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::4000 :::* LISTEN 31837/node8
if you try to run nodemon again it will crash!
kill the process using your port with kill 31837 in this case 31387 is the PID of node8 as you can see above
run nodemon again and it will work.
Adding the --signal SIGTERM to nodemon command line will kill the main process and all it's threads and should fix the problem.

Related

EADDRINUSE gets generated on every save with Nodemon

I use Ubuntu 20.04, Nodemon 2.0.4, Node 14.9.0 and Express 4.17.1. Every time I save my code I get this error:
events.js:291
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (net.js:1318:16)
at listenInCluster (net.js:1366:12)
at Server.listen (net.js:1452:7)
at Function.listen (/home/ubuntu/kopum/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/ubuntu/kopum/app.js:37:5)
at Module._compile (internal/modules/cjs/loader.js:1075:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1096:10)
at Module.load (internal/modules/cjs/loader.js:940:32)
at Function.Module._load (internal/modules/cjs/loader.js:781:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1345:8)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '::',
port: 3000
}
[nodemon] app crashed - waiting for file changes before starting...
And then I try to run this on terminal:
sudo lsof -i :3000
kill -9 {PID}
Then I restart the Nodemon by running nodemon app.js and everything's back to normal. But the EADDRINUSE is back again when I add some code and save it.
A simple fix that worked when I had a similar issue is to delay Nodemon's restart slightly:
nodemon --delay 500ms app.js
This seems to give a little time for ports to be correctly released.
Seems like nodemon does not correctly kill child-spawn processes before start;
Edit the scripts attribute in your package.json file and add a kill command to terminate any processes listening on your port before the server starts.
"scripts": {
"start": "npm run kill && nodemon app.js",
"kill": "kill -9 $(lsof -i :3000) &>/dev/null | exit 0"
}
try running npx kill-port 3000 after every save command

Error: EADDRINUSE on Mac - even though nothing is using the port?

Alexs-MacBook-Pro:build alexnordhausen$ gulp server:start
[21:11:22] Using gulpfile ~/Documents/Kanvasroom_Support/kanvasroom/build/gulpfile.js
[21:11:22] Starting 'env:dev'...
Application loaded using the "development" environment configuration
[21:11:22] Finished 'env:dev' after 6.25 ms
[21:11:22] Starting 'server:start'...
[21:11:22] Finished 'server:start' after 1.95 ms
[21:11:22] [nodemon] 1.11.0
[21:11:22] [nodemon] to restart at any time, enter `rs`
[21:11:22] [nodemon] watching: *.*
[21:11:22] [nodemon] starting `node --debug=5858 --trace-warnings server.js`
Server started, be sure the user content server is also running with gulp user-content
Live-build the client with gulp web:dist
Debugger listening on 127.0.0.1:5858
[Busy] Launching SocketCluster
Error: listen EADDRINUSE 127.0.0.1:5858
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at Agent.Server._listen2 (net.js:1262:14)
at listen (net.js:1298:10)
at doListening (net.js:1397:7)
at _combinedTickCallback (internal/process/next_tick.js:77:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
There aren't any ghost processes running... this was working just fine until I did a fresh npm install of the whole project. Thoughts?
As per the logs, you are using clustering. You might be trying to listen from each child process on same port, which will throw error after when second child process got launched.
I can see in your log:
Your master server started on 127.0.0.1:5858.
Then SocketCluster try to starting on 127.0.0.1:5858
So if you one server is already 5858 port, Then how can other server use 5858 ?
So plese change the port for solving the issue.
This error comes when more then two app using a single portno.
Use this command
1) `netstat -tulpn` (Commans for show all the process on server)
2) then kill the process with the process number. like kill 2043

How do you debug nodejs projects?

For the past 16 hours or so, I've been trying to get a MEAN stack project working on my computer.
I started with the Yeoman angular-fullstack project. But that was giving me all kinds of errors so I just gave up on it.
Then I followed some tutorials which helped me get started but didn't cover a ot of my questions.
Then I found mean.io which offers a full boilerplate MEAN stack project, which I followed the instructions to set up. Unfortunately, when I try to run it, I get all kinds of errors again :-(
The worst part about is, that it says NOTHING about what/where is causing the error.
Can someone help me figure it out? Please :-)
The latest error I'm getting is when I run grunt.
C:\Users\Imray\projects Practice\meanIO\meanApp>grunt
Running "hook" task
>> Starting hooked tasks.
Running "clean:0" (clean) task
>> 0 paths cleaned.
Running "jshint:all" (jshint) task
>> 42 files lint free.
Running "csslint:src" (csslint) task
>> 5 files lint free.
Running "concurrent:tasks" (concurrent) task
Running "watch" task
Waiting...
Running "nodemon:dev" (nodemon) task
[nodemon] v1.2.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node --debug server.js`
debugger listening on port 5858
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at Server.listen (net.js:1138:5)
at ExpressEngine.beginBootstrap (C:\Users\Imray\projects Practice\meanIO\meanApp\node_modules\meanio\lib\core_modules\server\E
xpressEngine.js:123:14)
at Meanio.serveWithDb (C:\Users\Imray\projects Practice\meanIO\meanApp\node_modules\meanio\lib\core_modules\server\index.js:14
:10)
at Consumer.Dependable.runAction (C:\Users\Imray\projects Practice\meanIO\meanApp\node_modules\meanio\node_modules\lazy-depend
able\index.js:72:22)
at Consumer.Dependable.fire (C:\Users\Imray\projects Practice\meanIO\meanApp\node_modules\meanio\node_modules\lazy-dependable\
index.js:69:53)
at Consumer.onResolved (C:\Users\Imray\projects Practice\meanIO\meanApp\node_modules\meanio\node_modules\lazy-dependable\index
.js:119:8)
at Consumer.Dependable.resolve (C:\Users\Imray\projects Practice\meanIO\meanApp\node_modules\meanio\node_modules\lazy-dependab
le\index.js:55:10)
[nodemon] app crashed - waiting for file changes before starting...
According to your output you have Error: listen EADDRINUSE.
It means that you already have running process on this port.
Try to investigate which process uses this port by typing:
sudo lsof -n -i4TCP:$PORT_NUMBER | grep LISTEN
Kill that process and restart your application.
If you need that process, change your application port.
EADDRINUSE is a low level system error, that usually means there's something else running on the port number you're using. Try using a different port.
EDIT: Note that it may not just be the actual server who's port is invalid. It looks like your deployment script creates a debugger, and possibly other services that listen on various ports, so they might need to be changed instead.
The problem went away after I restarted my computer. Not sure why, but I'll take it.

Node.js Unhandled 'error' event when using http.createServer().listen() on Ubuntu 12.04

Salam (means Hello) :)
I've developed a node.js script on my windows seven machine and it's working fine. but when I run it on my Ubuntu 12.04, the following error shows up and halts my app:
throw er; // Unhandled 'error' event
^
Error: listen EACCES
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1020:19)
at listen (net.js:1061:10)
at Server.listen (net.js:1127:5)
at Object.start (/httpServer/httpServer.js:9:34)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
and the point that caused error is .listen(80) in this line:
http.createServer(onRequest).listen(80);
^
I've also tried some other port numbers (like 100, 300, 500,...) instead of 80 and the error was still the same.
On Ubuntu you can't listen on ports < 1024 without root privileges. Try running node under sudo.
sudo node app.js
You probably have apache running on port 80, so it's conflicting.
Use another port (NOT within 0-1023), or disable apache.
Cheers
You probably have something else running on port 80, so it's conflicting.
Read here to find out what is using port 80 and stop it
http://www.cyberciti.biz/faq/find-linux-what-running-on-port-80-command/
Usually it means another server like apache is enabled. so stop it.
sudo service apache2 stop
or You have npm start already running in another terminal
or skype is running. in which case go to settings and change it's port. logout n login
Go to Tools -> Options -> Advanced -> Connections and uncheck the box "use port 80 and 443 as alternative".src
or use another port
http-server -a localhost -p 8000
I suggest to install the latest node packets, maybe directly from Node.js server, maybe compiling it.
Try to set a port which is not reserved to any service, like 3700.
Could be heplful to see some other fragment of code, though.
This can also be caused if you have something else already listening on that port - you can try changing the port from the typical default 80 to something more like 10014 and see if that helps!
I was able to rectify the error by explicitely mentionining the "IP address" along with the port when listening to the server.

ECONNREFUSED error while running express code

I am not able to run the server ...... I am getting the error as ECONNREFUSED
How to resolve this Error !
When i tried to use different ports .... all are giving me the same error !
ubuntu#ip-MyIP:~/rainmelon/projects/FindMyBuffet$ node app.js
Express server listening on port 7005
Error: connect ECONNREFUSED
at errnoException (net.js:884:11)
at Object.afterConnect [as oncomplete] (net.js:875:19)
--------------------
at Handshake.Sequence (/home/ubuntu/rainmelon/projects/FindMyBuffet/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:20)
at new Handshake (/home/ubuntu/rainmelon/projects/FindMyBuffet/node_modules/mysql/lib/protocol/sequences/Handshake.js:9:12)
at Protocol.handshake (/home/ubuntu/rainmelon/projects/FindMyBuffet/node_modules/mysql/lib/protocol/Protocol.js:42:50)
at Connection.connect (/home/ubuntu/rainmelon/projects/FindMyBuffet/node_modules/mysql/lib/Connection.js:73:18)
at Object.<anonymous> (/home/ubuntu/rainmelon/projects/FindMyBuffet/app.js:15:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
The traceback says where the exception is coming from:
Error: connect ECONNREFUSED
at errnoException (net.js:884:11)
at Object.afterConnect [as oncomplete] (net.js:875:19)
--------------------
...
at Connection.connect (.../node_modules/mysql/lib/Connection.js:73:18)
--> ^^^^^
at Object.<anonymous> (/home/ubuntu/rainmelon/projects/FindMyBuffet/app.js:15:12)
--> ^^^^^^^^^
So your app can't connect to MySQL.
This is usually down to either incorrect hostname/portname in your MySQL driver configuration, the MySQL server not running, or that your MySQL server isn't configured to listen on TCP sockets. See here.
Your mysql process is down, which means it is not running. You need to restart your mysql process (changing ports wont help).
To solve this problem you need to restart it. You can do by doing any of the following:
You can start your wamp or xamp server which will automatically start the process.
Or you can open the commandline prompt and start it manually like so "c:\wamp\bin\mysql\mysql5.5.24\bin\mysqld.exe"
Note that using the second method will require knowing the exact location of your wamp folder like I have used mine up top.(in quotes)
You may do a netstat to find out the pid of process running on the port 7005 and then go for a forceful kill with the pid got.
like
netstat -plten |grep 7005
kill -9 16085
where 16085 is the pid obtained from prev command. And restart the express app.
reference
How to kill a process running on particular port in Linux?

Resources