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?
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.
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.
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.
--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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With