I would like to run the following script using node --debug app.js
and have node wait for the remote debug session to start. I think the app.js
script is crashing before the debugger can make a connection. I'm using a tunnel to forward port 5858 to a vagrant box and I know that part is working as I have used the exact same setup successfully before.
Is this possible? The code is crashing at afterCheck(err,spam)) //spam is not defined
and I want to figure out why.
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '123',
database : 'kommunity',
debug: ['ComQueryPacket']
});
var akismet = require('akismet').client({ blog: 'deleted', apiKey: 'deleted' });
var selectPosts = "SELECT p.id as id, poster_ip, message, p.poster FROM topics t\
LEFT JOIN posts p on t.first_post_id = p.id WHERE poster_ip != ''";
//var spam = false;
akismet.verifyKey(function(err, verified) {
if(err) throw err;
if (verified) {
console.log('API key successfully verified.');
connection.connect();
connection.query(selectPosts, function(err, rows, fields) {
if (err) throw err;
var count = 0;
rows.forEach( function(entry) {
//console.log('foreach called with count '+count);
count++;
//console.log(entry['id']);
akismet.checkSpam({
user_ip: entry['poster_ip'],
comment_author: entry['poster'],
comment_content: entry['message']
}, afterCheck(err,spam))
});
});
}
else {
console.log('Unable to verify API key.');
}
});
var afterDelete = function (err, rows, fields) {
if (err) throw err;
console.log('deleted topic '+rows[0]);
console.log('spam');
connection.end();
}
var afterCheck = function(err, spam, entry) {
if(err) throw err;
console.log('after check called and spam is :'+spam);
var deleteQuery = "DELETE FROM topics , posts USING topics INNER JOIN posts \
WHERE topics.id=posts.topic_id AND topics.id ="
if(spam) {
console.log('spam');
console.log('entry is ' + entry);
connection.query(deleteQuery + entry.id + ';', afterDelete(err, rows, fields) );
connection.end();
} else {
console.log('Not spam');
}
}
From Webstorm Run/Debug Help. I know it because debug my nodejs apps in Webstorm.
With the --debug-brk option, the execution of the application suspends right after launch. This option allows you to debug the code executed on start.
With the --debug option, the code that has to be executed on the application start is executed whereupon the application waits for a debugger to connect to it. This option is useful when you are not going to debug Node.js right now, but you want to debug it later.
Update 2020-May
With node and npm versions --node 10.16.0 --npm 6.9.0, the --debug-brk option gives a deprecation warning.
(node:1601) [DEP0062] DeprecationWarning: `node --debug` and `node --debug-brk` are invalid. Please use `node --inspect` or `node --inspect-brk` instead.
We should use --inspect and --inspect-brk for this purpose.
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