假设我有一个nodejs应用,运行在AWS - 亚马逊云平台上(Amazone Web Service)。我想用本地的Visual Studio Code来远程调试服务器端的nodejs应用。
Visual Studio Code的调试配置里定义了两种类型,attach和launch。Visual Studio Code的官方文档对这两种调试启动行为的解释:
The best way to explain the difference between launch and attach is think of a launch configuration as a recipe for how to start your app in debug mode before VS Code attaches to it,
Launch的意思简而言之就是以debug模式启动app。
while an attachconfiguration is a recipe for how to connect VS Code’s debugger to an app or process that’s alreadyrunning.
而Attach的含义是将Visual Studio Code的调试器绑定到一个已经处于运行状态的应用。
因为我的需求是用本地的Visual Studio Code去调试AWS上正在运行的nodejs应用,毫无疑问应该选Attach。
点击debug configuration这个按钮:
自动弹出存放调试配置信息的launch.json文件了:
把launch.json的内容替换成下面的内容:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Jerry's first debug config",
"address": "127.0.0.1",
"port": 9221
}
]
}