Skip to Content
Author's profile photo Wouter Lemaire

Create CloudFoundry app with MongoDB and Express (NodeJS) in SAP Web IDE

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: 

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

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:

The result will look like this:



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


You can find the complete code of this blog on github:


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


Best regards,


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Suman Vanjre
      Suman Vanjre


      I have followed the above steps , successfully built and deployed to cloud foundry.

      When I run the app , i get the 502 Bad gateway error for the GET and POST services - that is for '/item' and '/items'.

      Please find the screenshot below and help to solve this. thank you.

      Author's profile photo Wouter Lemaire
      Wouter Lemaire
      Blog Post Author

      Can you check if mongodb is running?

      Author's profile photo Vishnu Vardhan Tanguturu
      Vishnu Vardhan Tanguturu

      Hi Lemaire,

      I have a similar issue. The status of mangodb is set to started.

      Author's profile photo Paige Ola
      Paige Ola

      Hi Wouter Lemaire and Vishnu Vardhan Tanguturu,

      have you found the solution for the problem of 502 bad gateway? I have the same problem here

      and really want to fix it.

      This is the app log I get. Can the db.collection function be the reason?

      2019-03-06T18:10:01.59+0100 [APP/PROC/WEB/0] ERR (node:67) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
      2019-03-06T18:10:01.63+0100 [APP/PROC/WEB/0] ERR /home/vcap/app/node_modules/mongodb/lib/operations/mongo_client_ops.js:474
      2019-03-06T18:10:01.63+0100 [APP/PROC/WEB/0] ERR throw err;
      2019-03-06T18:10:01.63+0100 [APP/PROC/WEB/0] ERR ^
      2019-03-06T18:10:01.63+0100 [APP/PROC/WEB/0] ERR TypeError: db.collection is not a function
      2019-03-06T18:10:01.63+0100 [APP/PROC/WEB/0] ERR at /home/vcap/app/server.js:37:18
      2019-03-06T18:10:01.63+0100 [APP/PROC/WEB/0] ERR at result 


      Best regards!