Debugging a bot
It is inevitable that eventually you will encounter a bug in your bot that is difficult to squash. The worst are bugs that don't cause your program to crash and thus don't provide a useful stack trace and line number for where the crash happened. For most issues, the console.log()
method will be enough to help you track down the bug, for the more tenacious bugs however we will need a true debugging environment. This section will introduce you to
iron-node
(https://s-a.github.io/iron-node/), a cross-platform JavaScript debugging environment based on Chrome's dev tools.
Start by installing iron-node
:
npm install -g iron-node
Note again the use of the -g
flag, which installs the application globally.
Before we can start debugging, we need to add a breakpoint to our code, which tells the debugger to stop the code and allow for deeper inspection. Add the debugger
statement to our previous code, within the slack.openDM()
code block:
if (/uptime/g.test(msg)) { debugger...