newBike
newBike

Reputation: 15002

Put breakpoint on node.js file

Hi I have a standalone script which should be run on commandline (not trigger by API request)

I can run this script this way node db.js

However, could I be able to put any breakpoint on this kind of script.

And stop at the breakpoint when debugging?

I can not imagine we can only use console.log to debug.

var mongoose = require('./db');
fs= require('fs');
var AppCtrl = require('../handlers/handlerModule.js');

AppCtrl.joinJSONFiles("DeltaAirlines",function (err, data) {
   data.forEach()
       ....
})

Upvotes: 3

Views: 2495

Answers (1)

qxz
qxz

Reputation: 3854

Reference: Debugger | Node.js v6.4.0 Documentation

Inserting the statement debugger; into the source code of a script will enable a breakpoint at that position in the code:

// myscript.js
x = 5;
setTimeout(() => {
  debugger;
  console.log('world');
}, 1000);
console.log('hello');

To use the debugger, run your program with node debug db.js. When a breakpoint is reached, the debugger prompt (debug>) appears. Some sample commands:

  • cont, c – continue execution
  • next, n – step next
  • backtrace, bt – print backtrace of current execution frame
  • exec expression – execute an expression in the debugging script's context
  • repl – open debugger's repl for evaluation in the debugging script's context

For a full list, see the Command reference section of the above link.

Upvotes: 3

Related Questions