欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

使用Visual Studio Code调试运行在SAP云平台上处于运行状态的nodejs应用

发布时间:2023/12/19 编程问答 46 豆豆
生活随笔 收集整理的这篇文章主要介绍了 使用Visual Studio Code调试运行在SAP云平台上处于运行状态的nodejs应用 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

https://blogs.sap.com/2020/11/23/debugging-nodejs-application-in-vscode-running-on-sap-cloud-foundry

该nodejs应用的package.json:

{"name": "debug-cloud","version": "1.0.0","description": "","main": "index.js","engines": {"node": "12.X" },"scripts": {"start": "node --inspect index.js","test": "echo \"Error: no test specified\" && exit 1"},"author": "","license": "ISC","dependencies": {"express": "^4.17.1"} }

index.js:

const express = require('express') const app = express()app.get('/debug', function(req, res){ res.send("Debug endpoint called")});// Start server app.listen(process.env.PORT || 8080, ()=>{})

为了部署这个nodejs应用,需要一个Manifest.yml:

--- applications: - name: debug-appmemory: 128Mrandom-route: truebuildpacks:- nodejs_buildpack

使用命令行部署应用:

cf login #Perform you login to your cf account -- a demo account works as wellcf push #push your application

给CloudFoundry space启用ssh支持:

cf enable-ssh <app-name> cf allow-space-ssh <space-name> cf restage <app-name>

重启应用。

在Visual Studio Code里添加一个launch configuration:

{"type": "node","request": "attach","name": "Attach cloud app ","address": "localhost","port": 9229,"localRoot": "${workspaceFolder}","remoteRoot": "/home/vcap/app"}

将一个本地端口号绑定到nodejs应用上:

cf ssh <APP_NAME> -N -T -L 9229:127.0.0.1:9229

上述命令行将远端服务器的9229端口绑定到本地计算机的9229端口。

现在就可以开始在本地Visual Studio Code里调试了:

总结

以上是生活随笔为你收集整理的使用Visual Studio Code调试运行在SAP云平台上处于运行状态的nodejs应用的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。