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()
....
})
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With