Вопрос: Как отлаживать приложения Node.js?

Как отладить серверное приложение Node.js?

Сейчас я в основном использую отладка предупреждений с такими заявлениями печати:


Должен быть лучший способ отладки. я знаю это Гугл Хром имеет отладчик командной строки. Этот отладчик доступен и для Node.js?




Узел-инспектор может спасти день! Используйте его из любого браузера, поддерживающего WebSocket , Точки останова, профилировщик, livecoding и т. Д. Это действительно потрясающе.

Установите его с помощью:

npm install -g node-inspector

Затем выполните:

node-debug app.js




  1. node --prof ./app.js
  2. node --prof-process ./the-generated-log-file





Библиотеки, выводящие отладочную информацию

Библиотеки, которые улучшают информацию трассировки стека




Они используются для работы, но больше не поддерживаются или больше не применимы к современным версиям узлов.


V8 отладчик, выпущенный как часть Google Инструменты разработчика Chrome может использоваться для отладки сценариев Node.js. Подробное объяснение того, как это работает, можно найти в Node.js GitHub wiki ,

Есть также приводная радиостанция , отладчик командной строки, написанный в самой Node.js.


Узел имеет свой собственный встроенный Отладчик GUI с версии 6.3 (с использованием DevTools от Chrome)

Nodes builtin GUI debugger

Просто передайте флаг инспектора, и вам будет предоставлен URL-адрес инспектора:

node --inspect server.js

Вы также можете пробить первую строку, пройдя --inspect-brkвместо.

Чтобы автоматически открыть окно Chrome, используйте осмотр-процесс модуль.

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

# start the debugger with inspect
inspect script.js


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

node debug script.js

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


I personally use JetBrains WebStorm as it's the only JavaScript IDE that I've found which is great for both frontend and backend JavaScript.

It works on multiple OS's and has Node.js debugging built-in (as well as a ton of other stuff](http://www.jetbrains.com/webstorm/features/index.html).

My only 'issues'/wishlist items are were:

  1. It seems to be more resource hungry on Mac than Windows It no longer seems an issue in version 6.
  2. It would be nice if it had Snippet support (like those of Sublime Text 2 - i.e. type 'fun' and tap 'tab' to put in a function. See @WickyNilliams comment below - With Live Templates you also have snippet support.


Visual Studio Code will be my choice for debugging. No overhead of installing any tools or npm install stuff. Just set the starting point of your app in package.json and VSCode will automatically create a configuration file inside your solution. It's build on Electron, on which editors like Atom are built.

VS Code gives similar debugging experience as you might have had in other IDEs like VS, Eclipse, etc.

enter image description here enter image description here


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.



A lot of great answers here, but I'd like to add my view (based on how my approach evolved)

Debug Logs

Let's face it, we all love a good console.log('Uh oh, if you reached here, you better run.') and sometimes that works great, so if you're reticent to move too far away from it at least add some bling to your logs with Visionmedia's debug.

Interactive Debugging

As handy as console logging can be, to debug professionally you need to roll up your sleeves and get stuck in. Set breakpoints, step through your code, inspect scopes and variables to see what's causing that weird behaviour. As others have mentioned, node-inspector really is the bees-knees. It does everything you can do with the built-in debugger, but using that familiar Chrome DevTools interface. If, like me, you use Webstorm, then here is a handy guide to debugging from there.

Stack Traces

By default, we can't trace a series of operations across different cycles of the event loop (ticks). To get around this have a look at longjohn (but not in production!).

Memory Leaks

With Node.js we can have a server process expected to stay up for considerable time. What do you do if you think it has sprung some nasty leaks? Use heapdump and Chrome DevTools to compare some snapshots and see what's changing.

For some useful articles, check out

If you feel like watching a video(s) then

Whatever path you choose, just be sure you understand how you are debugging

enter image description here

It is a painful thing
To look at your own trouble and know
That you yourself and no one else has made it

Sophocles, Ajax