Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node --debug-brk app.js not functioning

I'm trying to debug my app but something is stopping the app from actually firing up when I use --debug-brk flag.

Here's my output normally:

/usr/local/bin/node app.js
Express server listening on port 3000
Connected to database HackRegDb

Here's what happens when I run --debug-brk (with a breakpoint at a point in the code that won't be hit on initial startup)

/usr/local/bin/node --debug-brk=59763 app.js
debugger listening on port 59763

See, no "server listening" portion. The code is the same obviously, and there's no breakpoint before that is spit out.

For reference, here's my app.js file:

var express = require('express')
  , routes = require('./routes')
  , members = require('./routes/members')
  , teams = require('./routes/teams')
  , http = require('http')
  , path = require('path');

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

app.get('/', routes.index);
app.get('/members', members.list);
app.get('/teams', teams.list);
app.post('/members', members.add);
app.post('/teams', teams.add);
app.put('/members/:id', members.update);
app.put('/teams/:id', teams.update);

http.createServer(app).listen(app.get('port'), function(){
  console.log('Express server listening on port ' + app.get('port'));
});

Am I missing something?

like image 702
Chris Avatar asked Dec 04 '13 20:12

Chris


People also ask

How do I enable debug mode in node JS?

Open up Preferences > Settings and in the search box type in “node debug”. Under the Extensions tab there should be one extension titled “Node debug”. From here, click the first box: Debug > Node: Auto Attach and set the drop down to “on”. You're almost ready to go now.

Why is node js not working?

Make sure the node path is added, if not added it. After doing this restart Visual Studio or open a fresh command prompt. From the command prompt type 'node -v' to echo the node version installed. You can also add the path to node or any other application directly on the command line.

How do I use BRK inspect?

The port 9229 is the default debug port of the --inspect and --inspect-brk options. To use a different port (for example 12345 ), add it to the options like this: --inspect=12345 and --inspect-brk=12345 and change the port attribute in the launch configuration to match.


2 Answers

--debug-brk= stops the node program on the first line, meaning it will break before starting the server. You can then connect your debugger and hit Continue to run the program.

You can use --debug= to start the debugger but not break at the start. So if you have a debugger line somewhere in asynchronous code, it will still break when it hits it if your debugger is connected.

like image 93
loganfsmyth Avatar answered Oct 03 '22 14:10

loganfsmyth


Weird enough but this is what helped me.

I run the same command line but without -brk.

/usr/local/bin/node --debug=59763 app.js

The app finished successfully. And then the subsequent runs of the --debug-brk worked fine.

/usr/local/bin/node --debug-brk=59763 app.js
like image 28
Vasyl Boroviak Avatar answered Oct 03 '22 14:10

Vasyl Boroviak