Reputation: 15002
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
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 executionnext
, n
– step nextbacktrace
, bt
– print backtrace of current execution frameexec expression
– execute an expression in the debugging script's contextrepl
– open debugger's repl for evaluation in the debugging script's contextFor a full list, see the Command reference section of the above link.
Upvotes: 3