Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/419.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我如何在nodejs中调试,任何类似于pdb或Ruby或Python中的pry的工具_Javascript_Node.js - Fatal编程技术网

Javascript 我如何在nodejs中调试,任何类似于pdb或Ruby或Python中的pry的工具

Javascript 我如何在nodejs中调试,任何类似于pdb或Ruby或Python中的pry的工具,javascript,node.js,Javascript,Node.js,我用计算机运行我的脚本 node debug sample.js 它停在目标位置 不知何故,我不知道如何检查变量 例如,我想打印出变量db,但无法打印 在node.js 谢谢 sample.js 例外 20 21 }); 调试>打印(db) 答复:1 打印(db) ^ ReferenceError:未定义打印 回复:1:1 位于Object.exports.runInContext(vm.js:64:17) 在Interface.controlEval(_debugger.js:975:21)

我用计算机运行我的脚本

node debug sample.js

它停在目标位置

不知何故,我不知道如何检查变量

例如,我想打印出变量
db
,但无法打印

node.js

谢谢

sample.js 例外
20
21 });
调试>打印(db)
答复:1
打印(db)
^
ReferenceError:未定义打印
回复:1:1
位于Object.exports.runInContext(vm.js:64:17)
在Interface.controlEval(_debugger.js:975:21)
绑定时(domain.js:254:14)
在REPLServer.runBound[as eval](domain.js:267:12)
在服务器上。(回复js:279:12)
在REPLServer.emit上(events.js:107:17)
在REPLServer.Interface.\u在线(readline.js:214:10)
在REPLServer.Interface._行(readline.js:553:8)
在REPLServer.Interface.\u ttyWrite(readline.js:830:14)
调试>数据库
答复:1
分贝
^
ReferenceError:未定义数据库
回复:1:1
位于Object.exports.runInContext(vm.js:64:17)
在Interface.controlEval(_debugger.js:975:21)
绑定时(domain.js:254:14)
在REPLServer.runBound[as eval](domain.js:267:12)
在服务器上。(回复js:279:12)
在REPLServer.emit上(events.js:107:17)
在REPLServer.Interface.\u在线(readline.js:214:10)

您可能正在命令行调试器中查找“repl”命令。这也是将chrome的优秀开发工具连接到节点进程的好方法。您可以在my

中学习如何使用节点检查器,您可能想尝试一下(一个免费的、跨平台的、开源的IDE)。自8.1版以来,我们完全支持

Ok,我只编写了我的脚本,并将其作为简单的独立脚本运行。我没有想到我需要在webbrowser上调试。这比我想象的要复杂。谢谢:)命令行调试器也很好。您是否尝试在断点处暂停时键入
repl
,然后键入
console.log(db)
?检查变量在顶级命令集中不可用,您需要先
repl
。@LukAron已修复。
// Generated by CoffeeScript 1.9.2
(function() {
  var MongoClient, print;
  print = require('awesome-print');
  MongoClient = require('mongodb').MongoClient;
  MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
    debugger;
    db.command({
      listCollections: 1
    }, function(err, o) {
      debugger;
      return print(o["cursor"]);
    });
  });
}).call(this);
 20
 21 });
debug> print(db)
repl:1
print(db)
^
ReferenceError: print is not defined
    at repl:1:1
    at Object.exports.runInContext (vm.js:64:17)
    at Interface.controlEval (_debugger.js:975:21)
    at bound (domain.js:254:14)
    at REPLServer.runBound [as eval] (domain.js:267:12)
    at REPLServer.<anonymous> (repl.js:279:12)
    at REPLServer.emit (events.js:107:17)
    at REPLServer.Interface._onLine (readline.js:214:10)
    at REPLServer.Interface._line (readline.js:553:8)
    at REPLServer.Interface._ttyWrite (readline.js:830:14)
debug> db
repl:1
db
^
ReferenceError: db is not defined
    at repl:1:1
    at Object.exports.runInContext (vm.js:64:17)
    at Interface.controlEval (_debugger.js:975:21)
    at bound (domain.js:254:14)
    at REPLServer.runBound [as eval] (domain.js:267:12)
    at REPLServer.<anonymous> (repl.js:279:12)
    at REPLServer.emit (events.js:107:17)
    at REPLServer.Interface._onLine (readline.js:214:10)