How to do it...

There are two ways of doing debugging; let's see both methods here.

If you just want to stay in your IDE, Visual Studio Code lets you directly start a debugging session. Just click on the code you want to run (a reminder: pick the code in the out/ directory, and don't forget to use npm run build) and pick Debug | Start Debugging in the menu. The window will look as follows:

You can start a debugging session right in Visual Studio Code

Alternatively, if you'd rather keep using your favorite developer tools from Chrome, there's an alternative you can use. First, in Chrome, look for N.I.M., the Node.js V8 Inspector Manager, which can be found at https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj, and add it to your browser.

After doing that, open the N.I.M. console by going to about:inspect, and you'll get something like what's shown in the following screenshot:

 The N.I.M. extension lets you debug Node sessions using Chrome's developer tools

All you have to do now is go to VSC, or a shell session, and run your code. Before doing this, add the --inspect option, as in node --inspect out/restful_server.js. You will receive the following output:

 To connect Node to Chrome's developer tools, you must run your code with an extra --inspect option

After that, a window will open, and you'll have full access to Chrome's debugger console, as shown in the following screenshot:

If you examine the URL in Chrome's debugger, you'll see something like chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=..., followed by a URL and a (long) hexadecimal number. These values are listed after running Node with --inspect, in the line starting with "Debugger listening on ws...".

 If N.I.M. is enabled, your Node session will connect to it, and you'll be able to debug your code from within Chrome

Finally, in any case, you are ready to start a serious debugging session; let's see what you can do.

If you want to learn about how code inspection works, read the following article: https://nodejs.org/en/docs/guides/debugging-getting-started/. This also gives you tips for debugging with other IDEs.
..................Content has been hidden....................

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