Blogs.sap.com/2020/11/23/…

Package. json for the nodejs application:

{
  "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"}}Copy the code

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.() = >{})
Copy the code

To deploy the Nodejs application, you need a manifest.yml:

---
applications:
- name: debug-app
  memory: 128M
  random-route: true
  buildpacks:
    - nodejs_buildpack
Copy the code

Deploying the application using the command line:

cf login #Perform you login to your cf account -- a demo account works as well

cf push #push your application
Copy the code

SSH support for CloudFoundry Space

cf enable-ssh <app-name>
cf allow-space-ssh <space-name>
cf restage <app-name>
Copy the code

Restart the application.

Add launch Configuration to Visual Studio Code:

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

Bind a local port number to the Nodejs application:

Cf SSH <APP_NAME> -n-t -l 9229:127.0.0.1:9229Copy the code

The command line above binds port 9229 of the remote server to port 9229 of the local computer.

Now you can start debugging in native Visual Studio Code: