How do you debug nodejs projects? - node.js

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.

Related

nodemon is crashing after several changes done in project files?

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.

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

Mean.IO does not work on Redhat 6.5 VM

I am developing an application based on MEAN.IO, it works fine on my local Windows 7 machine, so I want to publish the app.
I have a remote Redhat 6.5 virtual machine (VM) server which can be used to host my application for public access. After uploading and run the app with grunt, it stops with an error:
$ 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: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
[nodemon] app crashed - waiting for file changes before starting...
I also tried to clone the code into the server directly from https://github.com/linnovate/mean.git, without ANY changes and run the app, but I got the same error as above.
I tried run node server.js instead of grunt, I got similar errors as below:
[jking#server eclipse_test]$ node server.js
for real!
forking 0
forking 1
forking 2
forking 3
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
Worker 3 died :(
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
Worker 2 died :(
...
__________________________________________________________
I don't know if it is due to the virtual machine or the mean.io stack.
Can someone give me any clue or answer to resolve it?
thanks
-John
I had the same problem and struggled all day with it until I found this:
https://forums.aws.amazon.com/thread.jspa?messageID=622248
Basically in my instance Amazon's linux image did not have the computer name associated with 127.0.0.1.
My instance was named ip-10-0-0-117 so I changed /etc/hosts from:
127.0.0.1 localhost localhost.localdomain
into
127.0.0.1 localhost localhost.localdomain ip-10-0-0-117
and everything works!

npm start giving error

I have installed KrakenJs on Windows 7. I have created project by using following command :
Yo Kraken
When I tried to run the project, it is giving following error (even after restarting system) :
E:\nodejs\test\kraken\Dust-01>npm start
> dust-01#0.1.0 start E:\nodejs\test\kraken\Dust-01
> node index.js
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 bind (E:\nodejs\test\kraken\Dust-01\node_modules\kraken-js\index.js:139:33)
at _fulfilled (E:\nodejs\test\kraken\Dust-01\node_modules\kraken-js\node_modules\q\q.js:798:54)
at self.promiseDispatch.done (E:\nodejs\test\kraken\Dust-01\node_modules\kraken-js\node_modules\
q\q.js:827:30)
at Promise.promise.promiseDispatch (E:\nodejs\test\kraken\Dust-01\node_modules\kraken-js\node_mo
dules\q\q.js:760:13)
at E:\nodejs\test\kraken\Dust-01\node_modules\kraken-js\node_modules\q\q.js:574:44
at flush (E:\nodejs\test\kraken\Dust-01\node_modules\kraken-js\node_modules\q\q.js:108:17)
E:\nodejs\test\kraken\Dust-01>
Can some one guide me what I am doing wrong and how it can be rectified
Look into next two possibilities:
Try opening your command prompt 'As Administrator', that shall solve the issue if you are lacking permissions to open port.
Temporarily change the port used in Kraken to something irregular and long, example: 32482
Then move on from this, if 1st - then you have solved an issue, if 2nd - you are very likely trying to open a port, which is already used by other application.

Emfile error running nodemon

Can't seem to get nodemon up and running.
It works when using just node (node app.js) but when using nodemon (nodemon app.js) the following Emfile error is returned:
20 Nov 12:26:33 - [nodemon] v0.7.10
20 Nov 12:26:33 - [nodemon] to restart at any time, enter `rs`
20 Nov 12:26:33 - [nodemon] watching: /home/ramzi/ST/swaggertrack
20 Nov 12:26:33 - [nodemon] starting `node app.js`
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
Express server listening on port 80
mongo is connected
EMFILE: Watching too many files.
EMFILE: Watching too many files.
EMFILE: Watching too many files.
EMFILE: Watching too many files.
Has anyone got any thoughts?
Thanks.
If you update to nodemon#1.0.12 (currently latest) it will warn out if there's too many files being watched (i.e. > 25,000 files - a rough arbitrary number I chose). If you don't get that warning, it's possible it's your script.
Happy to help debug (assuming you're on the latest version) at http://github.com/remy/nodemon/issues/new

Resources