Skip to Content

Hi all,

In addition to my previous blog, about deploying UI5 apps to CloudFoundry from the SAP Web IDE, I’ll show you how you can include MongoDB and Express (running on NodeJS) to the same app.

Previous blog: https://blogs.sap.com/2017/09/22/deploy-your-app-to-cloudfoundry-from-the-sap-web-ide-cp-trial/ 

In the current version of the SAP Web IDE trial account, there is no an option for adding NodeJS modules. The options described in this blog https://blogs.sap.com/2017/05/11/develop-a-full-stack-application-for-cf-using-sap-web-ide/ are not yet on the trial accounts available…

 

Although it isn’t available, it’s possible on CloudFoundry for trial accounts. Not sure if this is the best way, but this is how I made it work.

Start adding mongodb as a requirement of the html5 module in the mta.yaml file.

Open the package.json file in the html5 module

Add express to the dependencies and change the start script to start the app from “server.js”.

Express is a Node.js framework for web apps, read more on https://expressjs.com/

Add a file “server.js” to the html5 module.

In this file, we’ll use Express to access and expose mongodb. Server.js will also start the UI5 app by calling the folder webapp.

In the “server.js” file I define routes by using Express. Depending on the route, I’ll read and return the requested items from mongodb. The function to get the items from mongodb

I also define a path for a post request to create an item in mongodb

In the controller of our UI5 view I use ajax to fetch items from Express. Just using jQuery ajax for the example, other solutions are possible.

And an AJAX  POST to create an item

Follow the same steps from my previous blog to deploy the app: https://blogs.sap.com/2017/09/22/deploy-your-app-to-cloudfoundry-from-the-sap-web-ide-cp-trial/

The result will look like this:

https://<YourAccountName>-<Organization>-<CloudFoundrySpace>-<YourAppName>.cfapps.eu10.hana.ondemand.com/

https://<YourAccountName>-<Organization>-<CloudFoundrySpace>-<YourAppName>.cfapps.eu10.hana.ondemand.com/items

I used the CloudFoundry handson from UI5con for the code of Express and mongodb which you can find here:

https://github.com/frdrcbrg/ui5con-cf-todo

 

You can find the complete code of this blog on github: https://github.com/lemaiwo/WebIDECloudFoundryApp

 

Start having fun creating Cloud Foundry apps in the SAP Web IDE!

 

Best regards,

Wouter

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply