我想使用node --debug app.js
运行以下脚本,并让节点等待远程调试会话启动。我认为app.js
脚本在调试器建立连接之前崩溃了。我正在使用隧道将端口5858转发到一个流浪盒,我知道该部分正在工作,因为我之前已成功使用完全相同的设置。
这可能吗?代码在afterCheck(err,spam)) //spam is not defined
崩溃,我想找出原因。
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');
}
}
答案 0 :(得分:3)
来自Webstorm Run/Debug Help。我知道这是因为在Webstorm中调试我的nodejs应用程序。
使用--debug-brk选项,应用程序的执行暂停 发布后立即。此选项允许您调试执行的代码 一开始。
使用--debug选项,必须执行的代码 应用程序启动执行,然后应用程序等待 一个连接到它的调试器。如果不是,此选项很有用 现在要调试Node.js,但是你想稍后调试它。