在 VS Code 中尝试

Azure Node.js 远程调试

将 Visual Studio Code 调试器连接到运行在 Azure App ServiceLinux 上的 Node.js 应用。调试器的工作方式与连接到本地 Node.js 进程时相同 - 包括使用断点 (Breakpoints) 和日志点 (Logpoints)。

安装扩展

VS Code 的远程调试支持由适用于部署到 Azure 的应用的 Azure App Service 扩展提供。

Select App Service extension

安装 Azure App Service 扩展

  1. 通过按 ⇧⌘X(Windows、Linux Ctrl+Shift+X打开扩展视图。
  2. 搜索“azure app service”来过滤结果。
  3. 选择 Microsoft Azure App Service 扩展,然后选择安装

连接到 Azure

安装 Azure App Service 扩展后,您会注意到活动栏中添加了一个 Azure 视图。选择 Azure 视图以打开 Azure App Service Explorer。

App Service explorer

在 App Service Explorer 中选择登录 Azure 或从命令面板 (⇧⌘P(Windows、Linux Ctrl+Shift+P) 中选择 Azure: Sign In 来登录您的 Azure 帐户。如果您没有帐户,请选择创建 Azure 帐户... 来创建 Azure 免费帐户,以尝试任意组合的 Azure 服务。

提示:如果您尚未将应用部署到 Azure App Service,请先按照此教程将 Node.js + MongoDB Web 应用部署到 Azure

开始远程调试会话

要为您的应用开始远程调试会话,请在 App Service Explorer 中右键单击您的应用,然后选择启动远程调试

Start remote debugging

此过程需要启用调试器并重新启动应用。系统会提示您确认重新启动。

重新启动后,VS Code 通过 SSH 隧道连接到应用的调试端口。建立连接可能需要一些时间。连接成功后,VS Code 会切换到调试模式,并以与本地调试应用时相同的方式工作。

Remote breakpoint

当您准备结束远程调试会话时,像往常一样从调试器断开连接,并确认您要重新启动应用。

后续步骤

  • 日志点 (Logpoints) - 使用日志点记录到控制台,而无需在调试器中“中断”。
  • Azure 扩展 - VS Code 市场提供了数百个用于 Azure 和云的扩展。
  • 部署到 Azure - 逐步了解如何将应用部署到 Azure。