admin管理员组

文章数量:1327750

I ran my script by

node debug sample.js

It stopped at the target position.

Somehow, I don't know how to inspect the variables.

For example, I want to print out the variable db , but it couldn't.

Any remend debugger tool on node.js

Thanks

sample.js

// 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;
    dbmand({
      listCollections: 1
    }, function(err, o) {
      debugger;
      return print(o["cursor"]);
    });
  });
}).call(this);

exception

 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)

I ran my script by

node debug sample.js

It stopped at the target position.

Somehow, I don't know how to inspect the variables.

For example, I want to print out the variable db , but it couldn't.

Any remend debugger tool on node.js

Thanks

sample.js

// 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.mand({
      listCollections: 1
    }, function(err, o) {
      debugger;
      return print(o["cursor"]);
    });
  });
}).call(this);

exception

 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)
Share Improve this question asked Jul 15, 2015 at 2:31 newBikenewBike 15k29 gold badges117 silver badges204 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

2022 update

You can use node inspect

badloop.js:

let orders = [341, 454, 198, 264, 307];

let totalOrders = 0;

for (let i = 0; i <= orders.length; i++) {
  debugger; //Breakpoint
  totalOrders += orders[I];
}

console.log(totalOrders);

node inspect badloop.js

c or cont: Continue execution to the next breakpoint or to the end of the program.

n or next: Move to the next line of code.

s or step: Step into a function

o: Step out of a function

you can use the help mand inside de debugger to see all available mands.

You're probably looking for the "repl" mand in the mand-line debugger. Also node-inspector is a great way to hook up chrome's awesome devtools to a node process. You can learn how to use node-inspector in my blog post: Lighting up your javascript with the debugger

You might want to try CodeLite IDE (a free, cross platform, open source IDE). Since version 8.1 we fully support debugging Node.js applications

本文标签: