I have setup a web application that works and now I want to learn how to debug it properly without using console.log. I have setup and ran Node-Inspector via node-debug server.js (main script file) and I want to use and check what happens when I set up a breakpoint for an example in the following post function.
.post('/login', function (req, res){
var user = {
username: req.body.username,
password: hash(req.body.password)
};
db.findOne(user, function (err, data) {
if (data) {
req.session.userId = data.id;
res.redirect('/');
} else {
res.redirect('/login');
}
});
})
Node inspector works nicely and i'm familiar with it's design since using Google Chrome developer tools for basic JavaScript debugging (jQuery etc.) for some time. Everything looks good until I try to login into an application. Instead of breaking in for an example "var user" line it simply jst jumps into "timer.js" file in somesort of an setImmediate function. Even when i try to jump over i never get to that breaking point where I wish to see what does the post function contain inside a req, res variables etc.
I'm using NodeJS v0.12.2 and node-inspector 0.10.0.
I'm using body-parser, bourne, express and express-session modules in the project. Maybe worth mentioning that i'm running application on different port than 8080 or 5858 and I also have the specified code in another .js file if that may be somehow the case, since i can successfully breakpoint the first few (require) lines of the main server js file.
I don't know what to do or how to breakpoint a simple if statement wherever is stated. It just simply goes to somewhat timers.js and few step-overs it's done.
Any idea why is this happening?
Thanks in advance.
This is a known issue for node 0.12.* https://github.com/joyent/node/issues/25266
So, as a workaround you can use debugger
statement or switch to iojs for debuggind.
I also recommend you use NI 0.11.0. There implemented network debugging.