Exercise: Deploying TypeScript NestJS Application to SAP BTP

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Deploying TypeScript NestJS application to SAP BTP

Deploying TypeScript NestJS application to SAP BTP

Deploying application to SAP BTP

In this exercise, you will learn how to deploy the application to SAP BTP.

Prerequisites

For the complete execution of current exercise, you must execute the following activities first, using SAP Business Application Studio:

  1. Execute the following previous exercises:
    • Exercise Activating the APIs in SAP S/4HANA Cloud, this is needed only in case you want to connect the application to an SAP S/4HANA Cloud back end.
    • Exercise Creating your Pay-As-You-Go Account in SAP BTP, so that you have a SAP BTP account.
  2. Run the following commands in a terminal, in case you didn't do it already in previous exercises, to clone the Git repository for the course:
    Code snippet
    cd ~/projects
    git clone https://github.com/SAP-samples/cloud-sdk-learning-journey.git
    Expand

Steps

  1. Checkout the branch tsnestjs_v4.0_deploytocf in SAP Business Application Studio

    1. Open SAP Business Application Studio.

    2. Run the following commands in the terminal.

      Code snippet
      cd ~/projects/cloud-sdk-learning-journey
      git checkout tsnestjs_v4.0_deploytocf
      Expand
  2. Build and push the project to SAP BTP

    1. Build and push the application to SAP BTP by running the following commands in the terminal. Note: You will have to login to your SAP BTP Cloud Foundry account before running the cf commands

      Code snippet
      cd cloudsdk_bp_ts
      cf create-service destination lite mydestination
      cf create-service xsuaa application myxsuaa
      npm i
      npm run build
      cf push
      cf set-env cloudsdk_bp_ts DESTINATION_NAME bpdestination
      cf set-env cloudsdk_bp_ts APIKEY YOUR_APIKEY_GOES_HERE
      cf restage cloudsdk_bp_ts
      Expand
      Note
      You will have to login to your SAP BTP Cloud Foundry account before running the cf commands. Since the application depends on xsuaa and destination service, we need to create an instance of these services before deploying the application
    2. Verify that the application is successfully deployed in SAP BTP and the myxsuaa and mydestination services are bound to the application

  3. Query the Business Partner API of SAP S/4HANA Cloud

    1. Find out the URL of the application. After successful completion of the command cf push, the URL is displayed on the screen

    2. Create a destination named bpdestination in the SAP BTP subaccount with the following values

      FieldValue
      Namebpdestination
      TypeHTTP
      URLhttps://sandbox.api.sap.com/s4hanacloud
      Proxy TypeInternet
      AuthenticationNoAuthentication
    3. Open a new tab and browse to https://<application URL>/business-partner<application URL> is the URL you copied after executing the cf push command

    4. Verify that you are able to retrieve all the business partners

      Note
      The destination values can be modified to connect to an actual SAP S/4HANA Cloud system. Also, the SAP API Business Hub does not support CREATE, UPDATE operations
  4. Optional: Review code in the following source files

    1. Code walk-through

      File nameComments on code changes
      manifest.yml

      Configuration values are as follows...

      1. Provide basic application information like name, memory, timeout, path etc.
      2. Specify that the application depends on myxsuaa and mydestination services
      requests.httpProvides various HTTP requests that can be submitted to query the Business Partner API
      commands.txtProvides various commands that can be run on the terminal
  5. Optional: Manually create the project, without using the git branch, starting from the application you already created in the folder ~/projects/cloudsdk_bp_ts, within the previous exercise (Implementing CRUD operations in a TypeScript NestJS application).

    1. Choose FileOpen Folder... and open projects/cloudsdk_bp_ts.

    2. Create or update the following files in the table below

      File nameTypeContents
      business-partner.service.ts

      Path: ~/projects/cloudsdk_bp_ts/src/business-partner

      Modified

      Copy contents from here...

      manifest.yml

      Path: ~/projects/bpstandardvdm

      Modified

      Copy contents from here...

      package.json

      Path: ~/projects/bpstandardvdm

      ModifiedEdit the start:prod script to node dist/src/main
    3. Build and deploy the project in projects/cloudsdk_bp_ts in the same exact way you did in the previous steps with project in projects/cloud-sdk-learning-journey/cloudsdk_bp_ts.

Log in to track your progress & complete quizzes