不知道如何在 JetBrains WebStorm 中开始调试 Node.js 代码

Do not know how to start debugging a Node.js code in JetBrains WebStorm

我正在尝试学习调试 WebStorm 中的 Node.js 代码。代码是来自 here:

的简单 "Getting Started" 代码
const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

在我 运行 node app.js 在命令行并访问 http://localhost:3000. Next I tried to debug it locally in JetBrains WebStorm following instructions here 之后,上面的代码可以正常工作。这是 WebStorm 中 Node.js 应用程序的调试配置:

我单击错误图标 运行 调试模式下的 Node.js 代码。这是输出:

"C:\Program Files (x86)\JetBrains\WebStorm 10.0.3\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" --debug-brk=24163 --nolazy --inspect app.js
Debugger listening on ws://127.0.0.1:24163/bffa51bd-74bd-4257-8174-2c8ab3768e17
For help see https://nodejs.org/en/docs/inspector

我猜它等同于 运行 宁“node app.js”命令。该指令说我需要 "Perform the steps that will trigger the execution of the code with the breakpoints." 我想这意味着我在浏览器中打开 URL “http://localhost:3000” 以向 app.js 正在实施的 Web 服务器发送请求,我做到了。我已经在源代码的每一行设置了断点 app.js 并且我希望断点应该在源代码的某处命中,但是浏览器报告了一个 "Unable to connect" 错误并且 WebStorm 中没有发生任何事情 - 没有断点被击中。我已经检查了说明,但无法弄清楚我遗漏了什么。你能帮我解决这个问题吗?如果您需要更多信息,请告诉我。非常感谢!

PS: app.js 在 ...\test 文件夹中。

==编辑:==

PS2:浏览器可以打印"Hello world"只是因为"node app.js"仍然是运行ning。在我终止它之后,浏览器报告 "Unable to connect"。所以这意味着 URL 不知道如何连接到 WebStorm 调试器启动的网络服务器。是不是端口错了?

PS3:这就是http://localhost:31496/json/list中的returns(端口号在每个调试会话中都会改变)。希望能帮助解决问题。

description "node.js instance"
devtoolsFrontendUrl "chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:31496/0f03cac0-648f-4c13-9cb9-39bb5e3a81a6"
faviconUrl  "https://nodejs.org/static/favicon.ico"
id  "0f03cac0-648f-4c13-9cb9-39bb5e3a81a6"
title   "app.js"
type    "node"
url "file://E:..._test_app.js"
webSocketDebuggerUrl    "ws://127.0.0.1:31496/0f03cac0-648f-4c13-9cb9-39bb5e3a81a6"

据我所知,您使用的是 webStorm 10。它很旧,不支持最近 Node.js 更新中引入的新调试器协议。

请将 Node.js 降级到 v. 4.x(至少),或者最好将 Webstorm 升级到 2017.3