How to do it...

Let's follow these steps to add Chrome developer toolkit debugging to our Node.js application:

  1. First, we will update our debug NPM script in our package.json file to simply pass the --inspect-brk flag. This flag will replicate the same behavior as the Node.js debugger utility that pauses the execution context when the application starts. This is useful so that the asynchronous launching of the Chrome developer toolkit won't miss any important events that might happen on startup that you might want to debug:
{
...
"scripts": {
"clean": "rimraf ./dist",
"start": "node $NODE_DEBUG_OPTION ./dist/express.bundle.js",
"debug": "DEBUG=express* node --inspect-brk ./dist/express.bundle.js",
"build": "webpack",
"watch": "npm-run-all clean build --parallel watch:server watch:build --print-label",
"watch:build": "webpack --watch",
"watch:server": "nodemon ./dist/express.bundle.js --watch ./dist --on-change-only"
},
...
}
  1. After that, simply build and run your application:
npm run build
npm run debug
  1. If you have the Node.js V8 Inspector Manager installed, and Google Chrome is running in the background, you will note a new tab has been opened, which shows the source of your Express application's bundle in a paused state. Simply press the play button in your developer tools to continue:
  1. The debugger will stop at the next breakpoint which is inside our /src/Database.ts file. What is so interesting about this file is that it actually shows us the source map representation of this file instead of the actual compiled source in our WebPack bundle. This is very helpful to try to identify issues without the abstraction of looking at transformed source code, and this is possible due to Chrome's great source map support:
  1. Attempting to close this browser tab will automatically reopen the tab to the current debug context. Similarly, restarting the process will automatically reload the tab. To leave this tab, first close the Node.js debug process and then close the tab within your browser.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.116.102