Home  >  Article  >  Web Front-end  >  How to use Node.js+DevTools to quickly debug applications?

How to use Node.js+DevTools to quickly debug applications?

青灯夜游
青灯夜游forward
2021-09-26 10:25:261799browse

How to speed up debugging of Node.js applications? The following article will take you through how to use DevTools to speed up debugging Node.js applications. I hope it will be helpful to you!

How to use Node.js+DevTools to quickly debug applications?

When doing some Node related development, we often use Console to change the contents of variables Output to the console for viewing. It is still possible to view simple data, but when we encounter relatively large objects and many mounted attribute functions, the console may not be displayed, or even the content may be washed away. Seriously hindering our development efficiency, today we will use node-nightly to allow us to conveniently debug in Chrome and view our objects and Output log.

[Recommended learning: "nodejs Tutorial"]

Let’s take a look at the effect through a simple demonstration plug-in of webpack

Prepare node-nightly:

  • Install node-nightly: npm install --global node-nightly.

How to use Node.js+DevTools to quickly debug applications?

  • ##Execute node-nightly: node-nightly.

How to use Node.js+DevTools to quickly debug applications?

Start the entry script:

  • Execute the entry script through

    node-nightlynode-nightly --inspect-brk ./node_modules/webpack/bin/webpack.js, the script will break at the first statement and wait for operation.

  • Enter

    chrome://inspectOpen Chrome Inspect.

  • Enter inspect:

How to use Node.js+DevTools to quickly debug applications?

    ##The script is in a waiting state:

How to use Node.js+DevTools to quickly debug applications?

    Add the workspace of the current
  • node

    project in source, In the future, we can proceed as we originally did when debugging JavaScript in chrome.

How to use Node.js+DevTools to quickly debug applications?

How to use Node.js+DevTools to quickly debug applications?##The information in the Console is also printed out

How to use Node.js+DevTools to quickly debug applications?Supplementary instructions

Often our webpack configuration files will differentiate between different environments for special configurations,
    node -nightly
  • also allows us to add configuration after the executed command, such as:

    --config webpack.prod.js.

    Debugging our other simple
  • Node
  • single script will be easier, you can try it.

    If
  • node-nightly
  • is not working properly when running, we can install the specified version:

    node-nightly --version {version}or Install the latest arrangement: node-nightly --upgrade Try to fix the problem

    For more programming-related knowledge, please visit:
  • Programming Video
! !

The above is the detailed content of How to use Node.js+DevTools to quickly debug applications?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.cn. If there is any infringement, please contact admin@php.cn delete