A script that fails during startup is hard to debug, because by the time you attach a debugger the code has already run past the problem.
Start Node with --inspect-brk instead of plain --inspect:
node --inspect-brk app.js
Node opens the inspector on port 9229 and waits. Nothing in your script runs until a debugger connects, and then it stops on the first line. Open chrome://inspect in Chrome and click inspect under your script, or attach the debugger of your editor. From there you can set breakpoints and step through the startup code.
You can pick another port with node --inspect-brk=9230 app.js, which helps when two scripts run at once. For an npm script, pass the flag through node --inspect-brk node_modules/.bin/tool or set NODE_OPTIONS carefully, since it affects every child process.
A caveat: the inspector listens on localhost by default, which is what you want. Don’t bind it to 0.0.0.0 on a machine others can reach, because anyone who connects can run code inside your process.
Further reading: Node.js debugging guide