Skip to content

simonroloff/cloud-cf-helloworld-nodejs_copy

Repository files navigation

Chapter 1: Basic Implementation of a Node.js Web Service

Learning Goal

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.

Prerequisites

Step 1: Configure NPM on your machine to ensure all subsequent NPM calls work.

Execute the following command:

npm config set @sap:registry https://npm.sap.com

Step 2: Run the service locally.

  • 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 or http://<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 file SAP-CP-CF_Hello_World.postman_collection.json from this repository into Postman.  

Step 3: Push to Cloud and run the service.

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>.

About

cloud-cf-helloworld-nodejs_copy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published