Chapter 5. Customize the Cloud App
To better understand how the Cloud App works, make a minor modification to the code. Add a timestamp field with the value of the current UNIX time stamp to the server response. In the next section, you will modify the Client App to display the time stamp.
- Navigate to the Projects area using the navigation bar at the top.
- Open the My Hello World Project project.
- Open the Cloud App.
Click Editor on the sidebar on the left.
This area lets you edit the source code of any file in the Git repository of the Cloud App. The Cloud App in this project is a Node.js web application framework called Express.
Open the
application.jsfile.application.jshandles all requests to the Cloud App. The Client App sends requests to the/helloendpoint and theapplication.jsfile routes those requests to another file calledhello.js.app.use('/hello', require('./lib/hello.js')());To learn more about routing in Express, take a look at the Express Router documentation.
Change the lib/hello.js file to return a timestamp in the response.
-
Open
lib/hello.js. Add a
timestampproperty to the POST response object, with the value of the current UNIX time stamp.Find this line in the POST handler:
res.json({msg: 'Hello ' + world});Change that line to the following:
res.json({msg: 'Hello ' + world, timestamp: new Date().getTime() });The POST handler now looks like this:
hello.post('/', function(req, res) { console.log(new Date(), 'In hello route POST / req.body=', req.body); var world = req.body && req.body.hello ? req.body.hello : 'World'; // see http://expressjs.com/4x/api.html#res.json res.json({msg: 'Hello ' + world, timestamp: new Date().getTime() }); });Save your changes by clicking File > Save in the editor.
The changes are saved to the Git repository of the Cloud App. To propagate the changes to the running instance, you must re-deploy the Cloud App.
- Click Deploy on the sidebar on the left.
- Click Deploy Cloud App.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.