mitchkman
mitchkman

Reputation: 6680

Node.js callback not executed when using VSCode debugger

I have an issue with the VSCode Node.js debugger.

I have the following code (it downloads an image an calculates its hash):

var request = require('request');
var crypto = require('crypto');

request({ uri : 'http://static.wixstatic.com/media/28f6fa_1519eb247c97446098566248a9f86441.jpg', 
    encoding: null, 
    timeout: 10000 
    }, function (err, res, body) {
    if (err) {
        return res.status(500).send(err);
    }
    if (res.statusCode !== 200) {
        return res.status(500).send(buildResponse(500, "Image download returned status code " + res.statusCode));
    }
    console.log(crypto.createHmac('sha256', body).digest('hex'));
});

If I run node test.js, it prints the hash of the file perfectly. If I run it using VSCode debug mode, it does not.

If I set a break point at line 4 (request({...), the debugger hits the break point. If I set a break point at line 8 (if (err) { ...), the debugger does not hit the break point.

Am I doing something wrong or is this a bug?

$ node -v
v4.6.0

VSCode version: 1.6.1 Recovery Build

Upvotes: 0

Views: 604

Answers (1)

neko
neko

Reputation: 11

Just use the node-inspector it is for me the better way to debug code of backend

here is the link and there are complete guides to start witht that

https://www.npmjs.com/package/node-inspector

By the way is you want to debug some specific file use the node-debug

node-debug my_file_to_debug.js

I hope it help you.

Upvotes: 1

Related Questions