Having finished this chapter, you should be able to run a small Node.js Web service on your local machine and you'll be able to deploy it to SAP Cloud Platform Cloud Foundry Environment.
- You signed up for a trial account in SAP Cloud Platform, or you have a productive account.
- Once you got your account, you performed the steps described in Getting Started with Cloud Foundry.
- You have basic knowledge about Node.js: Development, for example, Create a Node.js Application and SAP NPM Registry. Please make sure that you bookmark these pages: Later SAP Node.js Packages and Secure Node.js Applications are also relevant.
- For more information about working with NPM registry, see this blog.
Execute the following command:
npm config set @sap:registry https://npm.sap.com
- Clone this repo to your machine.
- In the folder you cloned into, execute the
npm install
command. - To start the server, execute the
nodejs server.js
command. - To get all users or the details of one user, browse
http://<ip>:8088/users
orhttp://<ip>:8088/users/2
. - To add another entry to the list of users using the POST operation use, for example, the
Postman
extension of Chrome. (PUT and DELETE are not yet implemented). To test these operations, import the fileSAP-CP-CF_Hello_World.postman_collection.json
from this repository intoPostman
.
To log on, access your endpoint with the following command:
cf api https://api.cf.eu10.hana.ondemand.com
or:
cf api https://api.cf.us10.hana.ondemand.com
(depending upon the landscape your account was created in)
To log on use the following command:
cf login
If you have access to more than 1 org or space, execute the following command:
cf target -o ORG -s SPACE
To deploy the application to SAP Cloud Platform Cloud Foundry Environment, execute the following command:
cf push --random-route
For more information on these commands, see Getting Started with Cloud Foundry and Deploy an Application.
Check the output of this command, and write down the URL created for the application.
As a result you should be able to browse https://<URL for your app>/users
.
If you want to use the Postman
collection above, please adjust the URL for the requests in the Cloud folder to the allocated <URL for your app>
.