Skip to Content
Technical Articles
Author's profile photo ARJUN TOSHNIWAL

Deploying Applications into SAP BTP CloudFoundry: Part 1

Deploy NodeJS application : No Authentication

Tutorial Overview:

This blog describes the detailed steps required to deploy a basic nodejs application in SAP BTP (earlier know as SAP Cloud Platform) in cloud foundry environment.

This tutorial is divided into two parts:

  1. creating a basic nodejs application
  2. deploying a nodejs application in BTP (Business Technology Platform)

 

Let us create a new directory called : helloworld and navigate inside that directory
commands:

mkdir helloworld
cd helloworld

 

Step1 : Create a new nodejs project
commands:

npm init

It will create a package.json file with the content similar to this:

{
    "name": "helloworld",
    "version": "1.0.0",
    "description": "a simple nodejs application",
    "main": "index.js",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "author": "arjun toshniwal",
    "license": "ISC"
}

 

Step2 : Install approuter and configure it as a dependency
commands:
npm install @sap/approuter --save
It will add the following tag in package.json file:
{
  "dependencies": {
    "@sap/approuter": "^10.8.0"
  }
}

 

Step3 : Mention approuter as the start script of this nodejs application
"scripts": {
	"start": "node node_modules/@sap/approuter/approuter.js"
}
The updated package.json file would look like:
{
	"name": "helloworld",
	"version": "1.0.0",
	"description": "a simple nodejs application",
	"dependencies": {
		"@sap/approuter": "^10.9.1"
	},
	"scripts": {
		"start": "node node_modules/@sap/approuter/approuter.js"
	},
	"author": "arjun toshniwal",
	"license": "ISC"
}

 

Step4 : Create xs-app.json which is also known as router configuration file in the root directory
commands:
touch xs-app.json
It should contain the following information:
xs-app.json:
{
	"welcomeFile": "index.html",
	"authenticationMethod": "none"
}

 

Step5 : Create index.html file inside resources directory . This file would serve as a landing page in our application
commands:
mkdir resources
cd resource
touch index.html
index.html :
Hello World

 

Step6 : Create a manifest.yml file which is also known as deployment descriptor file in the root directory of the project
commands:
touch manifest.yml
manifest.yml:
---
applications:
- name: helloworld
  random-route: true
  buildpack: nodejs_buildpack
  memory: 512M
Note: The final package structure looks likes this:
|── helloworld
|  ├── resources
|         ├── index.html
|  ├── package.json
|  ├── xs-app.json
|  ├── manifest.yml

 

Step7 : Login via cf utility
command:
cf login -a <endpoint_url>
where endpoint_url can be found from :
Here it would be,
cf login -a api.cf.eu10.hana.ondemand.com

 

Step8 : Deploy the application into BPT via cf utlitiy:
commands:
cf push

It would give the following output:

cf%20push%20output

where as it can be seen the route of the deployed application is :
helloworld-busy-duiker-qp.cfapps.eu10.hana.ondemand.com

Note:
You can install the cli tools from:https://github.com/cloudfoundry/cli
Goto Download Section to download the cf cli

 

Step 9 : Run the deployed application

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Mamatha Majji
      Mamatha Majji

      Hello Arjun,

      It was very useful and informative blog, known about  AppRouter Usage to deploy Application in Cloud Environment(BTP).

      I followed all your steps mentioned in the blog. After Pushing the App to CF I am getting the follow errors. Could you please Assist me on this issue why I am getting like this:

       

      1)Error(Crashed)

      2)Deployemnt Info

      In Deployment Info I think I am not able to get the Buildpacks. It was showing empty. Even I am given buildpack name in manifest.yml file.

      3)In SAP BTP After uploading the Application to deploy the state was not getting Started. It was showing Starting... for longtime.

       

      SAP BTP

      4) Started State is showing as indication as Red. I hope if it goes to green color. The Application may get started. But it is showing as Crashed.

      My Project Structure is as follows:

      So could you please help me out this Issue. Present I am working on this it is very needful to achieve this task. Thanks in Advance!

      Regards,

      Mamatha M

      Author's profile photo ARJUN TOSHNIWAL
      ARJUN TOSHNIWAL
      Blog Post Author

      Can you please goto "Logs" and check the logs.

      It will give you exact cause of errors.

      If Buildpack has been given it should get detected . So lets check what it is giving us in "Logs"

      Author's profile photo Mamatha Majji
      Mamatha Majji

      Hello,

      Thanks for the Quick reply.

      After removing the excess code in package.json and xs-app.json files and I have created a Approuter folder separately for  "package.json" and xs-app.json files. Then the app was started.

      yeah I referred to error logs also it helped.

       

      Regards

      Mamatha