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?
--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.
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