If you have been working on HANA XSA development or SCP Cloud Foundry, chances are that you have been working exclusively using SAP WebIDE Full-stack, and this was the case for me, until I have noticed the popularity of VS Code and one day I decided to give it try and over the course of time it became clear to me what I’ve been missing all this while. The bottom line is that it helped to speed up my development time and be able to do advance debugging and troubleshooting. The only downside is that, there are some configuration steps you need to do to get started. This blog can help to get you started on testing your MTA-based app runtime, in which I will use nodejs runtime, using VS Code as a local development IDE while connected to SAP HANA DB in SAP Cloud Platform.
- Visual Studio Code Development IDE
- SAP Cloud Platform Account
- You already know how to build and deploy an MTA-based Application to SCP Cloud Foundry
Setup connection to HDI Container
This section describes the steps to connect your nodejs application to your already deployed HDI Container (SAP HANA DB) in SCP Cloud Foundry. It is already assumed here that you have deployed the HANA DB Artifacts into an HDI Container and we are now going to connect to that HDI container.
Let’s checkout first my sample project, which is the solution project for the hands-on exercise on openSAP course Software Development on SAP HANA 2019. You can browse the sample project in this GitHub Repo
Now, using the solution that is known to work using SAP WebIDE, let’s start to run the nodejs module in the folder called “XSJS”.
Right Click on XSJS folder > Open in Terminal > Execute command: npm run start
Notice that in the screenshot above, there were logs stating that no service found for HANA and therefore the OData services will be disabled. This problem is expected on a local development environment. And this is the part where we are going to start to setup the connection by following a few simple steps.
- 1. Go to your SCP Cockpit in Cloud Foundry and look for HDI Container service you want to connect to. Copy the “sensitive data” information (JSON data) because this contains the credentials that your nodejs application need to connect to this HCI Container.
- 2. Switch back to VS Code and create a file called “default-services.json” inside the XSJS folder. The content of the file should have a root property called “hana” and its value is the entire JSON data you copied from the SCP Cockpit. The resulting content should look like the one in the screenshot below:
You shouldn’t include default-services.json file in your commits to your project repository because this is used to contain the credentials of your HDI Container in SCP Cloud Foundry. And you shouldn’t commit any sensitive data into your code repository.
Make sure that you add an entry in the file “.gitignore” like the one below:
Luckily, the MTA Project template I generated from SAP WebIDE already included entry in .gitignore file for default-*.json. VS Code will display the files/folders in grey if they are ignore by git.
- 3. At this point, we are ready to run our nodejs application to check if we can connect to the HANA HDI Container.
Once again, run the command > npm run start
Notice that the problematic logs about not being able to connect to HANA service are now gone and take a look at the 2nd to last line of logs, it mentioned that the service is using an encrypted HANA connection. This means that the nodejs module is now connected to the HANA HDI Container! Woohoo!
- 4. The last thing to do is to test the application if it can really provide data from the HDI container. We can do this by doing query from an existing XSODATA service included in the sample project.
As you can see, the data is returned by the OData service, and this is the exact data coming from the HDI container.
Now we can say that it’s quite easy to setup a connection to an HDI container from our nodejs module. We didn’t even need to change anything in our existing code. The trick here is to make sure that you have conform to the service key (which is “hana”) in the default-services.json file and provide the necessary credentials as its value. The rest is taken cared of by the @sap/xsenv node module.
Now you know how to use VS Code and be able to connect to your HDI container. The next step is to dig into an advanced debugging and troubleshooting using VS Code debugger, and I will talk about this in my next blog. Stay tuned!
Update: here’s the continuation — Advanced debugging of MTA-based Apps