Change debug port for nodemon or mocha - node.js

I can use node-inspector to debug my nodemon app. But I want to also debug my tests. So I learnt that I need to start mocha in debug mode too (mocha --debug) problem is, this will try to debug on port 5858 by default too which in my case nodemon is using. So I will need to change the debug port of either, how do I do that?

Ok figured I can use mocha --debug=8101 to change mocha's debug port.

The same command line parameter works for nodemon and node. To bind on a different address, you can specify the IP like --debug=127.0.0.1:5858 (which is the default since Node.js v7), or use a wildcard --debug=[::]:5858 (which was the default in Node.js v6 and lower).

Related

Ember Server: "Port 4200 is already in use", when no process runs on 4200

When running my ember application with ember serve -e local I get:
Port 4200 is already in use.
Which is weird because no application is running on 4200. I tried to open a dummy HTTP server on 4200 with http-server and it works just fine. It also works when I specify the port via a command line flag ember serve --port 4200.
Some things I've tried:
Restarted my computer.
Removed the node_modules.
Remove the ember tmp directory.
Disabled my firewall.
Tried with disabled wi-fi.
Any thoughts?
I'm running on masOS High Sierra 10.13.6 with the following versions:
node: 8.11.3
ember-cli: 2.18.2
npm: 5.6.0 (also tried with 6.3.0)
Also useful to know:
I have other ember applications running on my computer just fine.
I started to have this problem only recently.
In the past, macOS would keep asking me about authorizing incoming traffic whenever an app was opened, but now it stopped asking me.
I had this issue and tracked it down to using a string vs. integer for port in .ember-cli.
// .ember-cli
{
"port": 8080, // works
"port": "8080", // throws the error mentioned above
}
Not sure if this is the cause for others with this error. As mentioned, first thing is to make sure nothing else is actually running on that port. But OP had already checked that, and so had I.
After further investigation, it seems that the problem is not coming from macOS, but from something messed up in the dependencies causing ember-cli to fail...
It's not quite clear what is causing this, and I will try to post any additional information here, but for now if you happen to encounter this problem, just pass the port value directly to ember-cli like so:
ember serve --port 4200

WebSockets request was expected error when using --inspect-brk option

When I run nodemon dist/server/app.js it works on default port 3000 and I'm able to reach my API. But if I run
nodemon --inspect-brk=localhost:3000 dist/server/app.js
I got error
WebSockets request was expected
What's wrong?
You can't run your web server and the debugger on the same port. They are each separate servers (the debugger is a server built into the node.js runtime).
So, you can either remove the port and host designation from the --inspect-brk option and just let it use the defaults (which is all I ever use) or you can select a different port for the debugger that doesn't conflict with your web server or anything else running on that host.

Debugging Kibana backend Node.js code

How to debug Kibana backend source code?
I presume, node-inspector could be used. And some extra configuration needed for package.json file to run debugger at npm start. But, I can't figure out the correct configuration syntax.
NODE_OPTIONS=--debug bin/kibana --dev
If you want to break before starting:
NODE_OPTIONS="--debug --debug-brk" bin/kibana --dev
Alternatively, you can set the same variable when calling npm start:
NODE_OPTIONS=--debug npm start
You will see:
Debugger listening on port 5858
You can then use the node inspector by running node-inspector and opening http://127.0.0.1:8080/debug?port=5858.
If you are debugging a remote server, you can either run node-inspector on the server and forward port 8080 through SSH, or you can run node-inspector locally and forward port 5858 through SSH.
EDIT: As it was now mentioned in the comments, it might be necessary to edit the source and add debugger; at the beginning, otherwise breakpoints might not work correctly even when using --debug-brk. Not sure why, though.
add $NODE_OPTIONS --no-warnings --inspect
and start kibana server and access the link shown in the logs like this link "chrome-devtools://devtools/remote/serve_file/#521e5b7e2b7cc66b4006a8a54cb9c4e57494a5ef/inspector.html?experiments=true&v8only=true&ws=localhost:5858/node" then you will find your backend code in the source tab and you can debug it like debuging frontend code.

Debugging node.js apps in WebStorm 7

I am having a strange issue debugging node.js apps in WebStorm 7.
The first time I start the debugger I get the application running:
/usr/bin/node --debug-brk=34041 app.js
debugger listening on port 34041
Current Environment: development
Express server listening on port 3000
But, after the first time (or if I restart the debugger), I get the debugger running but not the app, like below:
/usr/bin/node --debug-brk=42140 app.js
debugger listening on port 42140
or
/usr/bin/node --debug-brk=51341 app.js
debugger listening on port 51341
I need to restart the WebStorm itself in order to debug the app again.
Is it a bug in WebStorm?
Is it a bug in Node.js?
Is there a way to make it work properly?
After contacting the support, I found that it was a bug in the WebStorm, already fixed in version 7.0.1.

How do you get node-inspector to work?

Install:
npm install node-inspector
Run app:
node --debug-brk c:\users\me\desktop\myapp.js // app stops successfully
Run inspector:
node-inspector // doesnt work.
C:\Users\me\node_modules\.bin\node-inspector // does work.
Open chrome or safari and make sure debugger is on and navigate to localhost:5858. But this releases the app from the breakpoint and it doesn't show up anywhere inside chrome or safari.
Solution:
Go directly to http://​localhost:8080.
Port 5858 is the port that node-inspector uses to communicate with your node process; you don't access it directly. It speaks V8's raw debugging protocol.
inspector talks to your process via that protocol and serves up a HTTP website on 8080.
Also, npm should have put C:\Users\me\node_modules\.bin\ in your PATH. You might need a reboot for that to take effect, after which you should be able to just type node-inspector at a command prompt (rather than typing the whole path).
You need to visit http://localhost:8080/debug?port=5850 instead of http://localhost:5858.
Visit http://localhost:8080/debug?port=5858 to open the node-inspector console.

Resources