问题
I am trying to run node-inspector with an Express 4 App -- I am running this in a Vagrant box but am able to view the pages in the browser without any problems (I have the ports on the vagrant machine available to the host machine).
I fire up the application either with npm start
or node --debug bin/www
and then start the node-debugger bin/www
. I load the inspector in the browser and it hits the initial breakpoint on the first line but performing any action on the page to debug that would trigger a breakpoint causes an EADDRINUSE
(aka the port is in use) error. I'm a little baffled as to what could be causing this, however, it's very possible I'm using commands that would work on Express 3 instead of 4. Additionally, maybe there is some configuration I am missing to run the debugger on the browser of the host-machine but running inspector on the vagrant box?
回答1:
Update: I'm pretty sure this is your problem:
node --debug bin/www and then start the node-debugger bin/www.
Don't do BOTH of those. It's one or the other. They are 2 ways of doing the same thing. I prefer the former way as it's simpler and works with node itself whether or not you are using node-inspector.
To summarize:
node-debug bin/www
starts both your app in debug mode AND node-inspector in the same processnode --debug bin/www
starts your app in debug mode. This should be combined with a separate terminal window where you runnode-inspector
as a separate process. I recommend this approach, but either should work.
Here's my suggestion to start troubleshooting this. Try to use the simplest form of the commands to get everything running:
- in one ssh session terminal inside your vagrant host, start your app directly in the foreground with
node --debug ./bin/www
- v8 will try to bind to port 5858. You should see this message "debugger listening on port 5858" and NOT this message "Failed to open socket on port 5858, waiting 1000 ms before retrying"
- If you see the "Failed to open socket on port 5858" message, there's another process already listening. run
sudo netstat -ntlp
to see which process it is, comprehend what it is and why it is running, and then kill it to free up the portkill <pid-you-got-from-netstat>
- In a separate ssh session terminal inside your vagrant host, start the node-inspector web server
node-inspector
in the foreground. Make sure you see the normal output and no errors. - Now connect to the right URL which is probably something like
http://localhost:8080/debug?port=5858
(unless your vagrant IP/port are different) - if you get there and resolve any unexpected errors you see along the way, things really should work, but if not post some exact details about this
EADDRINUSE
error you see. Is that an exception within your app itself? If so, is there a stale instance of your express app already running somewhere else in your vagrant host and thus bound on your application's web server port?
回答2:
The same process works with supervisor.
来源:https://stackoverflow.com/questions/23797931/node-inspector-with-express-4