3
votes

The following file is started as node --debug-brk hello-http.js

hello-http.js

// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");

At the first line the program is expected to break and until the continue command is given using node-inspector(running on another terminal) the last line console.log("Server running at http://127.0.0.1:8000/"); is not supposed to be printed. But as soon as the node starts it does not break and prints the log.

$ node --debug-brk hello-http.js 
Debugger listening on port 5858
Server running at http://127.0.0.1:8000/

Using node version v0.12.0 running on a ubuntu-12.04 LTS machine How to make it break on the first line(i.e var http = require('http');).

UPDATE 1:

After rebooting the machine

  1. The node --debug-brk hello-http.js waits for the debugger to be connected as displayed

    $ node --debug-brk hello-http.js Debugger listening on port 5858

  2. node-inspector is stared on another terminal

  3. As soon the chrome browser connects to node-inspector at http://127.0.0.1:8080/debug?port=5858 the node programs continues execution(printing Server running at http://127.0.0.1:8000) with out waiting for the debugger to send commands.

    $ node --debug-brk hello-http.js Debugger listening on port 5858 Server running at http://127.0.0.1:8000/

Is this expected. If yes, how to make node-inspector send breakpoint command to set the breakpoint at the first line.

2
I can't reproduce this. Do you have a debugger running somewhere? Perhaps your debugger is making it move on right away?loganfsmyth
After reboot the node program waits for the debugger to connect. However as soon as the node-inspector connects the programs starts exectuing without stopping at the first line. Please look the update in the question.Talespin_Kit

2 Answers

2
votes

This is known issue of Node Inspector when running on a post-v0.10 version of Node (0.12, 1.x), see https://github.com/node-inspector/node-inspector/issues/534.