Translator: loveky

The original link

The Node.js trunk introduced new support for debugging in May.

Here’s how to get it and run it:

1. Download the daily build of Node

The following brief bash script will automatically help you download gist.github.com/paulirish/a…

curl -O ""https://gist.githubusercontent.com/paulirish/a02f4aa2b5ce69f5c269d18e74f57ab3/raw/36003214efb09259f86061656ac04ac846ff 9c2f/download-node-nightly.sh"" bash download-node-nightly.shCopy the code

In addition, you can find builds for the platform you are using here.

2. Add daily builds to your PATH

I prefer to rename the executable to Node-nightly *(so it doesn’t conflict with your everyday version)* and put it in the ~/bin directory.

Use 3.--inspectParameter execution code

node-nightly --inspect index.js
Copy the code

You can also use –debug-brk to break on the first line of the script.

node-nightly --inspect --debug-brk index.js
Copy the code

4. Open the provided URL

You’ll get one with Chrome-devtools ://.. String at the beginning. Paste this string into Chrome’s address bar and you’ll have all the features you’re familiar with with Chrome Devtools:

  • Full breakpoint debugging function, support for blackBoxing step debugging
  • Source Maps support for compiled code
  • Real-time editing: V8-based JavaScript hot plug support
  • Console with ES6 features/object support and customizable object formats
  • The JavaScript was sampled using Flamechart
  • Heap snapshot inspection, heap allocation timeline, heap allocation analysis
  • Asynchronous call stacks for native Promises

Enjoy!