Glen Arrowsmith Feb 2018 Brisjs.com twitter.com/garrows
Node.js Debugging
Node.js
LTS v8.9.4
The Lazy Way
console.log('A thing happened');
$ node app.js
A thing happened
Homework - console
The Better Lazy Way
const debug = require('util').debuglog('entity');
debug('A thing happened');
const debugEngine = require('util').debuglog('engine');
debugEngine('An engine thing');
$ node app.js
$ # nothing happened???
$ NODE_DEBUG=entity node app.js
ENTITY 21455: A thing happened
$ NODE_DEBUG=entity,engine node app
ENTITY 21497: A thing happened
ENGINE 21497: An engine thing
# Windows user?
set NODE_DEBUG=entity
Homework - Core Debug
Try setting NODE_DEBUG to a few of the
following to get core debug logs:
-
module
-
cluster
-
net
-
http
-
fs
-
tls
-
timers
... and checkout npmjs.com/package/debug
The Hard Way
console.log('Start');
for (var i = 0; i < 10; i++) {
console.log('i', i);
debugger;
}
console.log('End');
$ node debug app.js
The Old School Way
$ node --debug --debug-brk app.js
Debugger listening on [::]:5858
$ npm install -g node-inspector
$ node-inspector
Node Inspector v0.12.8
Visit http://127.0.0.1:8080/?port=5858 to start debugging.
$ node --debug --debug-brk app.js
Debugger listening on [::]:5858
The Cool Way
$ node --inspect --inspect-brk app.js
Debugger listening on ws://127.0.0.1:9229/09302d68-a88d-4fcf-a3e8-b00eb85b1d38
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
Where are my files?
Options...
Save edits
Util Debug StackTrace
Record CPU Profiles
Automatically Open Debugger
VS Code
VS Code
Homework - NodeUp
Listen to NodeUp's Podcast: 'Debugging Deep Dive'
Questions?
Glen Arrowsmith twitter.com/garrows
Node Debugging v8
By Glen Arrowsmith
Node Debugging v8
- 1,787