0

When I start my app using 'npm start' at the command line I can browse it at :3000

.. but not when I start it using 'node app.js'

when I try 'node --debug app.js' I get a console window with the message

"Debugger listening on port 5858"

With Visual Studio and the node toolkit I get the same. With Eclipse and Enide I get the same.

I've tried using Nodes built in command line debugger, but after the debug> prompt appears issuing the continue or next step commands does nothing, and I can't browse the app at :3000

I've installed node-inspector, and after 'node --debug app.js' I can see app.js in the node-inspector chrome tab :8080, but can't browse my app at :3000 and can't get breakpoints to work.

I guess that to get debugging working I need 'node app.js' to run, and not be using 'npm start'..

What important node configuration detail have I missed?

Why is my app not browsable when using 'node app.js' ?

Any advice is appreciated..

0

1 Answer 1

2

Your actually starting the app in two differnet ways using different code - one which includes the debugger and one that does not.

If your running a default Express 4 setup, if you check the package.json file you will see this section:

"scripts": {
    "start": "node ./bin/www"
  }

That is the file that is executed when you run npm start, so running node app.js is actually a different script.

If you take a look at bin/www you will see the debugger is invoked:

var debug = require('debug')('myapp');

To run use:

DEBUG=myapp ./bin/www

If you are starting using NPM, you can add it to the package.json or use exactly the same command from the cmd line:

"scripts": {
    "start": "DEBUG=myapp node ./bin/www"
  }
Sign up to request clarification or add additional context in comments.

4 Comments

Okay I see... 'npm start' is invoking the start script as defined in 'package.json', great that explains a lot... and I can tell visual studio/enide to use 'npm start' instead of 'node app.js' .... or use the command line... but where do I put 'DEBUG=myapp ./bin/www' so that node-inspector will attach? in the .bin/www script ?
@Kickaha I have not used node-inspector but it looks like you may be confusing the node-debug lib with the debug lib. Just had a real quick look at node-inspector and it looks like you just install globally and then kick it off using node-debug so node-debug ./bin/www should do it.
Okay I found that for Visual Studio I needed to hack the 'myApp.njsproj' project file to add bin/www as the startup file.. For Eclipse it is set in Run > Run Configurations > Node Configuration.. (I couldn't set breakpoints using Eclipse, but could use it in conjunction with node-inspector.. ) understanding that bin/www was a file and not a directory was key so cheers.. One other editor very good at express debugging I found was 'MS Code'. It's still in beta but is a much better tool for the job. I'll go back to the built in debugger if I need to debug in a terminal. Thanks again Ben.
Check out WebStorm (part of the intelliJ family). Its not free but by far the best IDE I have found for node. Great debug tools, integrated testing etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.