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:22

There is built-in command line debugger client within Node.js. Cloud 9 IDE have also pretty nice (visual) debugger.

查看更多
回忆,回不去的记忆
3楼-- · 2018-12-31 08:23

Theseus is a project by Adobe research which lets you debug your Node.js code in their Open Source editor Brackets. It has some interesting features like real-time code coverage, retroactive inspection, asynchronous call tree.

screenshot

查看更多
高级女魔头
4楼-- · 2018-12-31 08:24

There are many possibilities...

Debug support is often implemented using the v8 Debugging Protocol or the newer Chrome Debugging Protocol.

查看更多
冷夜・残月
5楼-- · 2018-12-31 08:25

I put together a short Node.js debugging primer on using the node-inspector for those who aren't sure where to get started.

查看更多
姐姐魅力值爆表
6楼-- · 2018-12-31 08:25

Use Webstorm! It's perfect for debugging Node.js applications. It has a built-in debugger. Check out the docs here: https://www.jetbrains.com/help/webstorm/2016.1/running-and-debugging-node-js.html

查看更多
像晚风撩人
7楼-- · 2018-12-31 08:26

node-inspector could save the day! Use it from any browser supporting WebSocket. Breakpoints, profiler, livecoding, etc... It is really awesome.

Install it with:

npm install -g node-inspector

Then run:

node-debug app.js
查看更多
登录 后发表回答