Node js question about debugging - Using Koa for Cadence-web - node.js

I started the debugger using :
$ node --inspect ../cadence-web/server/routes.js
Debugger listening on ws://127.0.0.1:9229/e470a53c-480b-497e-8494-5f1ea62f3b38
Now - I inspect chrome: The code is successfully opened in the debugger.
Please see link below
I open dedicated devTools for Node
Please see link below
I go to localhost:9229: The site cannot be reached.
Any help will be appreciated.
What am I doing incorrectly. Why is the code not loaded on localhost: 9229

The port mentioned in the startup is the Debugger port where the Debugger (Web Tools or VSCode etc.) listens to node. It is not the port your web server is using. That port hasn't changed from its setting in code. Check your source, it should be there, something like 3000 or 8080, depending on your framework and settings

Related

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.

Meteor always listens on port 3000

I created a new Meteor project in WebStorm on Windows 8.
In "Run/Debug Configurations" I set the port value to 3008, but when I run the app, it always works on port 3000.
Does anybody know where Meteor defines the port number or how can I change it?
I've searched the words "3000", "PORT" and "listen" in the entire project but they don't exist.
I've also seen these questions which didn't help me because they use Express which defines the port number hard-coded:
Node.js/Express.js App Only Works on Port 3000 ,
Express is listening on port 3000 despite setting it to 80?
Any help will be profoundly appreciated!
Try passing -p 3008 as a program argument in Meteor run configuration:
http://localhost:3008 in Browser/Live Edit tab is just used for browser launching (i.e. it tells WebStorm to launch the browser with specified URL), it's not supposed to affect Meteor port in any way

node-inspector --webhost is not local! its a web app

if I enter
node --debug /home/engine/public_html/myapp.js
then in another putty tab
node-inspector --webhost http://website.com
I still get it telling me to open the browser and look locally...
Node Inspector v0.7.0-2
info - socket.io started
Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.
Where as my site is online not local. When I do go to this address that inspector is telling me chrome says
This webpage is not available
I have opened ports 5858 and 8080 I can't see how this is suppose to work.
Even i get the localhost url when I try to debug my remote site using node-inspector.
Try visiting the url http://website.com/debug?port=port_number after you start the inspector and app.
Here are the steps:
Start the Node Inspector server
$ node-inspector --web-port=5050
Enable debug mode in your Node process
$ node --debug=5050 app.js
Load the debugger UI
Open http://website.com/debug?port=5050 in the Chrome browser.

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 debug a Node.js server running with Chrome/WebKit as the remote debugger?

If you have your Node running
node --debug server.js
This gives me a port number xxxx, should I use this port number when starting Chrome?
Do you remote debug into it from Google\ Chrome --remote-debugging-port=xxxx?
Or is the 9222 a magic port, as it is mentioned all over.
Am I on the right track, trying to start Chrome with --remote-debugger into the Node.js server.js
The node-inspector / --debug are now replaced by inspector
See update below
#now deprecated / see below for update
#install node-inspector
npm install -g node-inspector
#start node-inspector, listen on port 8080 (default)
node-inspector --web-port=8080
#in another terminal session/window:
#while node-inspector is running, start your project in debug mode
node --debug myproject.js
Now you can browse to http://your_server:8080 for a full debug session of myproject.js
If your remote server is not accessible on the remote port because of firewalls or other reasons, you could create an ssh-tunnel to it from port 8080 on your local machine to 'localhost:8080' on the remote server:
ssh -L 8080:localhost:8080 username#remoteserver -N
and keep this running while you use http://localhost:8080 on your local machine to debug your remote nodejs session
Update august 2017
Start node in inspect mode:
node --inspect=0.0.0.0:9229 myproject.js
or if you want the debugger to break at the first line of myproject.js:
node --inspect-brk=0.0.0.0:9229 myproject.js
Then open the following URL in your chrome browser:
chrome://inspect
Click the 'Configure...' button and add the following target:
ip-or-name-of-server-running-node:9229
After you click the 'Done' button, you should see myproject.js under your remote targets. Click the inspect link to start debugging. Unfortunately, the inspect link does not work on Chrome 58 for Ubuntu. It works fine on Chrome 60 for Windows.
Use node-inspector to remotely debug your node application from Chrome that you've started with the --debug option as you've shown.
Recent versions of Node (> v6.3.0) and Chrome now allow you to use the Chrome Developer Tools to debug a Node.JS process without having to install anything else. Just pass --inspect to node:
$ node --inspect script.js
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
chrome-devtools://SOME-URL-HERE
Just open that URL in Chrome, and you're good to go.
If you need to pause your script immediately after Node starts, you can also pass --debug-brk in the same command.
using
$ vagrant ssh -- -L 5858:127.0.0.1:5858
to ssh connect to VM. also this comment would start a proxy server on port 5858;
you could test using telnet 127.0.0.1 5858 to see if local proxy server started or not.
In VM, you can start node with command
$ node --debug-brk app.js
set up debug configuration in web storm.
when you start debug in web storm, node.js server in VM will start in a few seconds.
PS: there is no need to touch the vagrant file.
Reference: Connecting WebStorm to a remote node.js debugging session.

Resources