How do I debug Node.js applications?

2018-12-31 07:36发布

How do I debug a Node.js server application?

Right now I'm mostly using alert debugging with print statements like this:

sys.puts(sys.inspect(someVariable));

There must be a better way to debug. I know that Google Chrome has a command-line debugger. Is this debugger available for Node.js as well?

30条回答
骚的不知所云
2楼-- · 2018-12-31 08:33

Node.js version 0.3.4+ has built-in debugging support.

node debug script.js

Manual: http://nodejs.org/api/debugger.html

查看更多
心情的温度
3楼-- · 2018-12-31 08:33

Use this commands

DEBUG_LEVEL=all node file.js
DEBUG=* node file.js
node file.js --inspect
查看更多
只若初见
4楼-- · 2018-12-31 08:34

Node has its own built in GUI debugger as of version 6.3 (using Chrome's DevTools)

Nodes builtin GUI debugger

Simply pass the inspector flag and you'll be provided with a URL to the inspector:

node --inspect server.js

You can also break on the first line by passing --inspect-brk instead.

To open a Chrome window automatically, use the inspect-process module.

# install inspect-process globally
npm install -g inspect-process

# start the debugger with inspect
inspect script.js
查看更多
梦醉为红颜
5楼-- · 2018-12-31 08:34

Visual Studio Code has really nice Node.js debugging support. It is free, open source and cross-platform and runs on Linux, OS X and Windows.

You can even debug grunt and gulp tasks, should you need to...

查看更多
浮光初槿花落
6楼-- · 2018-12-31 08:34

The NetBeans IDE has had Node.js support since version 8.1:

<...>

New Feature Highlights

Node.js Application Development

  • New Node.js project wizard
  • New Node.js Express wizard
  • Enhanced JavaScript Editor
  • New support for running Node.js applications
  • New support for debugging Node.js applications.

<...>

Additional references:

  1. NetBeans Wiki / NewAndNoteworthyNB81.
  2. Node.js Express App in NetBeans IDE, Geertjan-Oracle.
查看更多
高级女魔头
7楼-- · 2018-12-31 08:35

Visual Studio Code will work for us in debugging.

查看更多
登录 后发表回答