gpt4 book ai didi

javascript - 我可以让 nodejs --debug 标志等待远程连接吗

转载 作者:搜寻专家 更新时间:2023-10-31 23:47:22 26 4
gpt4 key购买 nike

我想使用 node --debug app.js 运行以下脚本,并让 node 等待远程调试 session 启动。我认为 app.js 脚本在调试器可以建立连接之前崩溃了。我正在使用隧道将端口 5858 转发到一个 vagrant box,我知道这部分工作正常,因为我之前成功地使用了完全相同的设置。

这可能吗?代码在 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');

}
}

最佳答案

来自 Webstorm Run/Debug Help .我知道它是因为在 Webstorm 中调试我的 nodejs 应用程序。

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.

2020 年 5 月更新

对于 node 和 npm 版本 --node 10.16.0 --npm 6.9.0,--debug-brk 选项给出弃用警告。

(node:1601) [DEP0062] DeprecationWarning: `node --debug` and `node --debug-brk` are invalid. Please use `node --inspect` or `node --inspect-brk` instead.

为此,我们应该使用 --inspect 和 --inspect-brk。

关于javascript - 我可以让 nodejs --debug 标志等待远程连接吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34084751/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com