Creating your first Express application
Express is a Node.js web framework. It allows rapid development of web applications. It provides an easy way to handle routing of an application by exposing REST APIs.
In this chapter, you create an application that uses the Express framework and the Watson Natural Language Understanding service to extract the author name from articles that are published on the web. You provide the web address (URL) of the article to the application, and it outputs the name of the author (or multiple names if the article has multiple authors).
This chapter contains the following topics:
3.1 Getting started
To start, read through the objectives, prerequisites, and expected results of this use case.
3.1.1 Objectives
Express is a Node.js web framework. It allows rapid development of web applications. It provides an easy way to handle routing of an application by exposing REST APIs.
By the end of this chapter, you should be able to accomplish these objectives:
Create a Hello World Express application.
Create a simple HTML view for your application.
Understand Express routing.
Use third-party modules in Node.js.
Understand IBM Watson Natural Language Understanding service.
Use a Git repository on IBM Cloud DevOps.
Understand Delivery Pipeline.
3.1.2 Prerequisites
Before you start, be sure that you meet these prerequisites:
Basic JavaScript skills
Basic HTML skills
A workstation that has these components:
 – Internet access
 – Web browser: Google Chrome or Mozilla Firefox
 – Operating system: Linux, Mac OS, or Microsoft Windows
3.1.3 Expected results
You create an application that uses Express framework and Watson Natural Language Understanding service to extract the author name from any article that is published on the web. You provide the web address (URL) of the article, and the application outputs the name of the author (or multiple names if the article has multiple authors).
The application involves the following steps:
1. Figure 3-1 shows the starting page of the application. Enter the web address of any article, such as the following URL, and then click Submit. In this example, the URL of the article is as follows:
Figure 3-1 Watson Author Finder
2. The URL of the article is posted to the /author URL (Figure 3-2), then Watson Natural Language Understanding service is called to extract the author name (or names) from the article.
Figure 3-2 Watson Author Finder returned these results
3.2 Architecture
Figure 3-3 shows the components and runtime flow of the application.
Figure 3-3 Architecture
The following steps explain the sequence of interactions between the various components in the exercise:
1. In a web browser, navigate to the application URL of this exercise:
http://vy102-XXX-express.mybluemix.net
2. The web browser sends a GET request to the Node.js server. As mentioned in step 1, the application URL for this example is http://vy102-XXX-express.mybluemix.net. The path that follows this URL is a route, and there should be a handler for this route in the Node.js application.
For example, if the user sends the following request, there should be a route called 'GET /sample' in the Node.js application:
http://vy102-XXX-express.mybluemix.net/sample
This route can return a resource (HTML page, image, and so on), call a back-end service, or both.
In step 1, the user requested the home page of this exercise’s application. The browser sends a GET request to http://vy102-XXX-express.mybluemix.net/. That means that the 'GET /' (root) route will be called.
3. The Express framework in Node.js returns the index.html file in response to the 'GET /' route request.
4. The web browser shows the index.html page to the user. The index.html page contains a form that has one text box, and a Submit button. In the text box, the user can enter the URL of the article.
5. The user enters the article’s URL, and then clicks Submit.
6. The web browser sends a POST request to the /author route with the article URL passed in the body.
7. Express framework in Node.js passes the article URL to Watson Natural Language Understanding service. Also, it requests that the metadata be returned.
 
Note: The Watson Natural Language Understanding service uses natural language processing (NLP) to analyze semantic features of any text. The Natural Language Understanding service has many features, such as concepts, categories, emotion, entities, keywords, metadata, and sentiment.
The feature that you use in this exercise is metadata.The feature gets document metadata, including author name, title, RSS and Atom feeds, prominent page image, and publication date.
8. The metadata of the article is returned by the Natural Language Understanding service.
9. Node.js filters the metadata to return only the author name (or names).
10. The author name (or names) of the article are returned to the user on the web browser.
3.3 Step-by-step implementation
This section provides details of how to implement the Hello World Node.js app by using the Express framework.
3.3.1 Log in to your IBM Cloud account
Log in to IBM Cloud by completing these steps:
1. Open your web browser, enter the following web address, and then press Enter:
2. The IBM Cloud login page opens (Figure 3-4). Click Log in and provide your authentication credentials.
Figure 3-4 IBM Cloud login
3.3.2 Create the Node.js application on IBM Cloud
Complete these steps to create the Node.js app by using the IBM SDK for Node.js runtime on IBM Cloud and to enable continuous delivery for the application:
1. Click Catalog on the top bar and select Cloud Foundry Apps on the left pane.
2. Click SDK for Node.js (Figure 3-5).
Figure 3-5 IBM Cloud Catalog: Cloud Foundry Apps
3. In the App name field, type vy102-XXX-express (Figure 3-6). Replace XXX with any three random characters. Click Create.
Figure 3-6 Create an SDK for Node.js application
4. In the next steps, you enable continuous delivery for this application. Application Details displays the Getting started page (Figure 3-7). Wait until the application is started and then click Overview.
Figure 3-7 Application details: Getting started page
5. In the Continuous delivery tile of the Overview page, click Enable (Figure 3-8).
Figure 3-8 Application details: Overview page
6. A new tab opens (Figure 3-9) where you create a toolchain. In the Repository type field, select New to create an empty application, and then click Create.
Figure 3-9 Create a toolchain
7. To start editing the code, click Eclipse Orion Web IDE (Figure 3-10).
Figure 3-10 IBM Cloud DevOps toolchain
8. On the left, expand the twistie for vy102-xxx-express (highlighted in Figure 3-11).
Figure 3-11 Eclipse Orion
Notice that an empty project is created (Figure 3-12).
Figure 3-12 An empty project is created: vy102-xxx-express
3.3.3 Create the Hello World Express application
Express is a Node.js framework. It is used to simplify the creation of web applications on Node.js. The core component of Express is routes.
Route refers to the definition of application end points (Uniform Resource Identifiers (URIs)) and how they respond to client requests. Express supports the routing methods that correspond to the HTTP methods GET, POST, PUT, HEAD, DELETE, OPTIONS, and TRACE.
In the following steps, you create the Hello World Express application that returns the words “Hello Express!” in response to the GET / route request. The root (/) route is called whenever a user accesses the URL of the application. Also, you will create another route, POST /author, after the user sends a POST request to the /author resource. This route returns “Author Name” to the user.
1. Create the package.json file and add Express framework as one of its dependencies:
a. Right-click vy102-xxx-express in the left navigation bar, and select New  File.
b. Name the file package.json (Figure 3-13) and then press Enter.
Figure 3-13 The empty package.json file
c. Copy the code snippet from Example 3-1 to the package.json file.
Example 3-1 Code snippet: package.json
{
"name": "vy102-XXX-express",
"version": "0.0.1",
"description": "A sample express app",
"dependencies": {
"express": "4.*"
}
}
d. Notice that Express version 4.x is added as a dependency. In the name, replace XXX with the three characters that you assigned as part of your application name (Figure 3-14).
Figure 3-14 The package.json file with the Express version 4.x dependency
2. Create the app.js file. In app.js, you create an instance of Express and it will be the starting point of your application:
a. In the navigation bar, right-click vy102-xxx-express, and then select New  File.
b. Name the file app.js and press Enter. At this point, app.js is empty (Figure 3-15).
Figure 3-15 The empty app.js file
c. Copy the code snippet from Example 3-2 into the app.js file.
Example 3-2 Code snippet: Instantiate Express framework (GET and POST)
var port = process.env.VCAP_APP_PORT || 8080;
 
//Express Web Framework, and create a new express server
var express = require('express'),
app = express();
 
// In case the caller calls GET to the root '/', return 'Hello Express!'.
app.get('/', function(req, res) {
res.send('Hello Express!');
});
 
// In case the caller calls POST to /author, return 'Author name'
app.post('/author', function(req, res) {
res.send('Author name');
});
 
// start server on the specified port and binding host
app.listen(port);
The code instantiates the Express framework, listening to the default port of IBM Cloud, and exposes two routes (Figure 3-16):
GET / Returns “Hello Express!” to the caller when the caller requests the root of the application.
POST /author When the caller issues a post request to /author, “Author name” is returned.
Figure 3-16 The app.js file with Express starter code
 
Note: You can usually press Shift+Alt+F to format the code.
3. Add the manifest.yml file with the domain and host, and configure it to run app.js after the Node.js server starts:
a. Right-click vy102-xxx-express in the left navigation bar, and then select New  File.
b. Name the file manifest.yml and press Enter.
c. Copy the code snippet from Example 3-3 to the manifest.yml file. This code configures the domain, name, and memory of the application.
In the manifest.yml file, replace XXX with the three characters you chose as part of your application name and host.
Example 3-3 Code snippet: Add domain and host, and configure to run app.js
applications:
- path: .
memory: 256M
instances: 1
domain: mybluemix.net
name: vy102-XXX-express
host: vy102-XXX-express
 
disk_quota: 1024M
d. If needed, change the domain on based on your IBM Cloud region as listed in Table 3-1.
Table 3-1 IBM Cloud regions and domains
Region
Domain
US South
mybluemix.net
United Kingdom
eu-gb.mybluemix.net
Sydney
syd.mybluemix.net
Germany
eu-de.mybluemix.net
e. Copy the following line to the end of the manifest.yml file. This line instructs IBM Cloud to start app.js after the application is staged.
command: node app
Your manifest.yml now looks like the file in Figure 3-17.
Figure 3-17 The manifest.yml file
The file is saved automatically. You can force save it by clicking File  Save.
4. Deploy the application from the workspace by completing these steps:
a. In the server toolbar, select Create new launch configuration from the drop-down list. If you do not have the Create new launch configuration option, skip to step d.
b. Click the “+” button to display the Edit Launch Configuration window.
c. In the Edit Launch Configuration window, ensure that the Organization is set to your email address, and Space is set to dev, and click Save.
d. Click the play icon (Deploy the App from the Workspace), which is highlighted in Figure 3-18. Then, click OK in the window that opens to confirm the action.
Figure 3-18 Deploy the application
e. Notice that the Live Edit and debug options are visible on the top toolbar after the deployment is completed (Figure 3-19). The Live Edit and debug features are available only for the Node.js application. When IBM Cloud detects that you are creating a Node.js application (from the manifest.yml file), the two features become available on the toolbar.
 
Note: IBM Cloud Lite account does not support the Live Edit feature. If you are using a Lite account, this option will not be displayed.
Figure 3-19 The Live Edit and debug features are now available
 
Note: While a Node.js application is in Live Edit mode, you can debug it on the Web IDE. You can edit code dynamically, insert breakpoints, step through code, restart the runtime, and more. You must use a Chrome browser to be able to use the debug feature.
5. Run the application by clicking the Open the Deployed App icon (Figure 3-20).
Figure 3-20 Open the application
A new tab opens with the application, and the “Hello Express!” text is returned (Figure 3-21).
Figure 3-21 The Hello Express application
3.3.4 Create a simple HTML view and organize the code
In the next steps, you create a simple HTML page that has a form where the user enters the URL of the article. When the user clicks Submit, the article URL is posted to /author in the request body.
You will also organize the code by creating routing modules instead of having the routing handled in the app.js file.
Complete these steps:
1. Add views/index.html as the starting page (Figure 3-22):
a. Close the browser tab where the application is running.
b. Right-click vy102-xxx-express on the left bar, and select New  Folder.
c. Name the folder views, and then press Enter.
d. Right-click the views folder on the left bar, and select New  File.
e. Name the file index.html, and then press Enter.
Figure 3-22 Empty index.html file
2. Copy the code snippet from Example 3-4 into the index.html file.
Example 3-4 Code snippet: HTML
<html>
 
<body>
<h1 style="color:blue;">Watson Author Finder</h1>
<p>To get information about the author of an article, enter the URL of that article.</p>
<form action="author" method="post">
<input type="text" name="url" />
<input type="submit" value="Submit" />
</form>
</body>
 
</html>
The HTML code indicates the following information:
 • A heading that contains the words “Watson Author Finder” in blue.
 • A paragraph that instructs the user what to do.
 • A form that contains a text field and a Submit button. Upon submission, the parameters are submitted in the form of x-www-form-urlencoded in the body. In this code snippet, the only parameter is the URL of the article. The URL is submitted as a POST method to the author action, which triggers the POST /author route.
The index.html file now looks like the one shown in Figure 3-23.
Figure 3-23 The content of the index.html file
3. In app.js, change the root route (GET /) to send the index.html page to the caller:
a. Open app.js from the left navigation bar.
b. Add the following code snippet after the line that contains app = express();.
This code snippet references the path module. The path module provides utilities for handling the directories, so it must point to the index.html file.
var path = require('path');
c. Update the callback function for / route, which is the line after app.get('/', function(req, res) {. Change the code so that the callback function returns the index.html page instead of the words Hello Express!:
res.sendFile(path.join(__dirname, 'views/index.html'));
Also, change the comment before the line app.get('/', function(req, res) { to the following text:
// In case the caller calls GET to the root '/',
// return the content of index.html
Figure 3-24 shows the app.js file with your updates.
Figure 3-24 Updated app.js
4. To be able to receive the request parameter, you must add a module named body-parser. The body-parser middleware module parses the data and populates the request object with the data under the req.body module. Complete these steps:
a. After the line that contains var path = require('path');, add a reference to the third-party body-parser module:
var bodyParser = require('body-parser');
 
//parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
b. Hover the cursor over body-parser and notice the warning message that is generated by Eclipse Orion Web IDE (Figure 3-25). The message indicates that the body-parser module is not defined in package.json.
Figure 3-25 Missing module in package.json warning
c. You can either update package.json manually to add dependencies to body-parser or click Update package.json, which updates the dependencies automatically.
Open the package.json file and update the dependencies as shown in Example 3-5.
 
Note: Make sure that you add a comma after the express dependency line, as shown in the example
Example 3-5 Add body-parser
"dependencies": {
"express": "4.*",
"body-parser": "*"
}
d. Open app.js and update the callback function for the POST /author route to send the URL to the user in response to post /author instead of sending Author name. Replace res.send('Author name'); with the code snippet in Example 3-6.
Example 3-6 Code snippet: Send URL to user
res.send('You called the server requesting the author of the article: ' + req.body.url);
Change the comment before the line app.post('/author', function(req, res) { to the following text:
// In case the caller calls POST to /author, return the url of the article
e. Press Shift + Alt + F to format the code. Your updated app.js is shown in Figure 3-26.
Figure 3-26 Updated app.js file
5. In this step, you organize the code by moving all the routing to the routes module:
a. Right-click vy102-xxx-express on the left navigation bar, and then select New  Folder. Name the folder routes and press Enter.
b. Create index.js to handle all the routing related to the root resource, right-click the routes folder, select New  File, name the file index.js, and then press Enter.
c. Copy the code snippet from Example 3-7 and paste it into the index.js file.
Example 3-7 Code snippet: Using expres.Router
// index.js - Index route module
var express = require('express');
var router = express.Router();
 
//Provides utilities for dealing with directories
var path = require('path');
 
// Home page route
router.get('/', function (req, res) {
res.sendFile(path.join(__dirname, '../views/index.html'));
});
 
module.exports = router;
This code snippet uses express.Router, which is introduced in Express 4 and provides an isolated instance of routes. It is used here to define an endpoint (URI) that handles the routing when a user sends a GET request to the home page of the application for this exercise.
The updated index.js file is shown in Figure 3-27.
Figure 3-27 Updated index.js file
d. Create an author.js file to handle all the routing related to the /author resource. Right-click the routes folder, select New  File, name the file author.js, and then press Enter.
e. Copy the code snippet from Example 3-8 into the author.js file.
Example 3-8 Code snippet: Add to author.js file
// author.js - Author route module
var express = require('express');
var router = express.Router();
 
router.post('/', function (req, res) {
res.send('You called the server requesting the author of the article: ' + req.body.url);
});
 
module.exports = router;
Figure 3-28 shows the updated author.js file.
Figure 3-28 Updated author.js file
f. Edit app.js to configure Express to use the index and author route modules:
i. Click app.js on the left navigation bar.
ii. Find lines of code between the comments // In case the caller calls GET and // start server on the specified port and binding host.
iii. Replace those lines, including the comment // In case the caller calls GET with the code snippet from Example 3-9. Remove any unintended line breaks, especially in the comments, after pasting the code.
Example 3-9 Code snippet: Use app.js to bind routing modules
//Routes modules
var index = require('./routes'),
author = require('./routes/author');
//In case the caller access any URI under the root /, call index route
app.use('/', index);
 
//In case the caller access any URI under /author, call author route
app.use('/author', author);
This example uses app.js to bind the routing modules that you defined previously with specific paths. The handling of the routing of any URI under root (/) is handled by the index routing module, and the handling of the routing of any URI under /author is handled by the author routing module.
Your updated app.js file is shown in Figure 3-29.
Figure 3-29 Updated app.js
6. Deploy the application and run it by completing these steps:
a. Click the Play icon (Deploy the App from the Workspace) on the top toolbar to deploy the app. Confirm that you want to restart the app if prompted to do so.
b. Wait for the deployment to complete.
c. Click the Open the Deployed App icon on the top toolbar to run the application.
The application opens in your browser (Figure 3-30).
Figure 3-30 Running the application
d. In the text box, enter the URL for an article of your choice and click Submit.
The route POST /author is then called (Figure 3-31).
In this example, the following URL was used for testing:
https://www.forbes.com/sites/alexkonrad/2016/01/29/new-ibm-watson-chief-david-kenny-talks-his-plans-for-ai-as-a-service-and-the-weather-company-sale
Figure 3-31 Author page
3.3.5 Integrate with Watson Natural Language Understanding service
The default Node.js framework includes only a minimal set of features. However, a large community of developers add to the Node.js framework through third-party libraries.
In this section, you extract the author name by calling the Watson Natural Language Understanding service. IBM Watson services provide REST APIs that you can use to add cognitive capabilities to your applications.
Natural Language Understanding uses natural NLP to analyze semantic features of any text, which can be plain text, HTML, or a public URL. Natural Language Understanding returns results for the features that you specify. The feature that you use in this exercise is metadata. It gets document metadata, including author name, title, RSS/Atom feeds, prominent page image, and publication date.
In Node.js, the Watson APIs are wrapped inside a third-party module that is named watson-developer-cloud that you will use in this exercise. The watson-developer-cloud module is developed and maintained by IBM. It is a third-party module because it is not developed as part of the Node.js foundation, and not packed into Node.js by default. To include the watson-developer-cloud module, you must add it as a dependency in the package.json file.
Complete these steps:
1. In this step, you add the Watson Natural Language Understanding service and bind it to the application.
IBM Cloud services are a set of capabilities or functions delivered over the Internet that IBM Cloud hosts and manages. You can add services from the IBM Cloud catalog to your IBM Cloud application. Services provide a predefined endpoint that you can access from your application. The infrastructure for services is completely managed by IBM Cloud, and your app only must use the provided endpoint.
You will bind the Natural Language Understanding service to your application so your application can use it by completing these steps:
a. Close the running application tab and go back to the IBM Cloud DevOps page.
b. Right-click Catalog and select Open link in new tab (Figure 3-32).
Figure 3-32 Eclipse Orion
c. In the IBM Cloud Catalog, click Natural Language Understanding (Figure 3-33).
Figure 3-33 Catalog - Selecting Natural Language Understanding
The Natural Language Understanding page opens (Figure 3-34).
Figure 3-34 Natural Language Understanding creation page
d. Change the Service name field to natural-language-understanding. This is the name of the service.
e. Click Create.
f. Click Connections on the left pane.
g. Click Create connection, select your application vy102-XXX-express, and click Connect (Figure 3-35).
Figure 3-35 Connect the Natural Language Understanding service with the application
 
Important step: You must perform this step because it binds the instance of the Natural Language Understanding service to the application so that your application can use the service.
h. To make the service available for use, click Restage on the dialog window that opens (Figure 3-36). Restaging the application means redeploying the application.
Figure 3-36 Restage app dialog box
i. Close the Service Details tab to return to IBM Cloud DevOps.
2. For integration with Watson, you will be using a module named watson-developer-cloud. Add a dependency for it in the package.json file:
a. Open the package.json file.
b. Add watson-developer-cloud as a dependency in package.json:
i. Find the line “body-parser”: “*” (it can also be “body-parser”: “latest” if added automatically before). Add a comma (,) at the end of the line and press Enter.
ii. On the new line, add the following code snippet:
"watson-developer-cloud": "2.25.1"
The updated package.json is shown in Figure 3-37.
Figure 3-37 Updated package.json
3. Create a module named articleServices to handle all the business logic related to articles. This module has the function extractArticleAuthorNames that calls the Natural Language Understanding service, passing to it the article URL, and returning the list of author names. Complete these steps:
a. Right-click vy102-xxx-express in the left navigation bar and then select New  Folder. Name the folder services, and then press Enter.
b. Create articleServices.js. Right-click the services folder, select New  File, name the file articleServices.js, and press Enter.
c. Create an instance of the third-party node.js module watson-developer-cloud by copying the code snippet from Example 3-10 to the articleServices.js file.
Example 3-10 Code snippet: Create instance of third-party Node.js module
// Watson Natural Language Understanding third party module
//Specify the release for the Natural Language Understanding service
var NaturalLanguageUnderstandingV1 = require('watson-developer-cloud/natural-language-understanding/v1.js');
var natural_language_understanding = new NaturalLanguageUnderstandingV1({
'version_date': NaturalLanguageUnderstandingV1.VERSION_DATE_2017_02_27
});
 
 
Unknown dependency: Eclipse Orion might raise an unknown dependency warning message. You can ignore this warning because the parent module, watson-developer-cloud, was included previously. The watson-developer-cloud module contains the natural-language-understanding module.
d. Create a function, extractArticleAuthorNames (Example 3-11) that calls the Natural Language Understanding service to extract the authors’ names.
Example 3-11 Code snippet: extractArticleAuthorNames function
 
/*
* Call Watson NLU Service to extract the list of author names for the requested article URL
*/
exports.extractArticleAuthorNames = function(req){
};
4. Prepare the parameters for calling the Natural Language Understanding service by placing the code snippet from Example 3-12 inside the extractArticleAuthorNames function.
Example 3-12 Code snippet: Parameters for calling Watson NLU
 
// url is the parameter passed in the POST request to /author
// It contains the URL of the article
// The metadata feature returns the author, title, and publication date.
var parameters = {
'url': req.body.url,
'features': {
'metadata': {}
}
};
5. Call the Natural Language Understanding service and return to the caller a callback function that contains the author’s name. Complete these steps:
a. Add callback as a parameter to the function:
exports.extractArticleAuthorNames = function(req, callback){
b. Call the analyze function from the natural_language_understanding third-party module. If the request succeeds, it returns a metadata object of the article. In this exercise, you are interested in the authors object in the metadata that returns the list of authors for the article.
Copy the code snippet from Example 3-13 to the extractArticleAuthorNames function after the parameters variable initialization.
Example 3-13 Code snippet: Call the Natural Language Understanding service and return caller
// Call the Watson service and return the list of authors
natural_language_understanding.analyze(parameters, function(err, response) {
if (err)
callback(err,null);
else
callback(null,response.metadata.authors);
});
6. If the URL passed is empty, return an error message to the user:
a. Add the following error message as a constant after the initialization of the natural_language_understanding variable:
//error message for missing URL
const MISSING_URL_ERROR = 'URL not passed';
b. Check whether the URL is empty. At the beginning of the extractAuthorNames function (line exports.extractArticleAuthorNames = function(req, callback){), add the code snippet from Example 3-14 to return the error message if the URL is not defined.
Example 3-14 Check URL
//If the url is not passed, return error to the caller
if(req===null||req.body===null||req.body.url===null){
callback(MISSING_URL_ERROR,null);
return;
}
c. Press Alt + Shift + F to format the code.
The complete articleServices.js file now looks like the file in Figure 3-38.
Figure 3-38 The full code of the articleService.js file
7. Edit the author route to call authorServices.extractArticleAuthorNames instead of just returning the article URL by completing these steps:
a. From the navigation bar, open the routes folder and select the author.js file.
b. Add a reference to the authorServices module after the router variable initialization:
var articleServices = require('../services/articleServices');
c. Edit / route to call the extractArticleAuthorNames function from the articleServices module. This process involves replacing the line res.send('You called the server requesting the author of the article: ' + req.body.url); with the code snippet from Example 3-15.
Example 3-15 Code snippet: Add call to extractArticcleAuthorNames function
articleServices.extractArticleAuthorNames(req, function(err, response) {
if (err)
res.status(500).send('error: ' + err);
else
res.send(response);
});
The code indicates that in case of error, a 500 status code is returned to the user, which means Internal Server Error.
The updated author.js file is shown in Figure 3-39.
Figure 3-39 Updated author.js
3.3.6 Deploy the application and run it
Other ways to deploy the application exist in addition to deploying it from Eclipse Orion Web IDE. In the next steps, you push the code to the Git repository, and then the IBM Cloud Delivery Pipeline automatically builds and deploys the code.
By default, enabling continuous delivery for a project creates a DevOps toolchain for your project. The toolchain includes a Git repository that is based on GitLab. Git is an open source change management system.
The Git repository perspective in the IBM Cloud DevOps Services web IDE supports common Git commands to manage your code. You can also develop your application on your own workstation and commit your changes to the Git repository with a standard Git client.
By default, IBM Cloud Delivery Pipeline services automatically run the build and deploy tasks when you commit changes to the Git repository.
Complete these steps:
1. Switch to the Git perspective by clicking the Git icon on the left toolbar (highlighted in Figure 3-40).
Figure 3-40 IBM Cloud DevOps
2. Notice that all the changed files are listed in the Working Directory Changes window (Figure 3-41). Enter a descriptive message for commit, for example Watson Author Finder - Initial Code, and then click Commit.
 
Figure 3-41 IBM Cloud DevOps: Git
3. Your change is displayed in the outgoing window (Figure 3-42). Click Push.
Figure 3-42 IBM Cloud DevOps: Git
4. After the application is pushed to Git, the Delivery pipeline automatically builds and deploys the application. Complete these steps:
a. Close the IBM Cloud DevOps Git tab and return to the Application Details.
b. Scroll down to the Continuous delivery tile and then click View toolchain (Figure 3-43).
Figure 3-43 Application Details
c. Click Delivery Pipeline (Figure 3-44).
Figure 3-44 IBM Cloud DevOps toolchain
d. Wait until all the jobs at the Build Stage and Deploy Stage are completed. Figure 3-45 shows that the Deploy Stage is still running.
Figure 3-45 Delivery Pipeline: Deploy Stage is in-progress
Figure 3-46 shows that both stages are completed.
Figure 3-46 Delivery Pipeline: Build Stage and Deploy Stage passed
e. To run the application, click the URL of the last execution result of the Deploy Stage (Figure 3-47).
Figure 3-47 Delivery Pipeline: Click URL
f. Run the application by entering the URL of any article and then clicking Submit (Figure 3-48).
The following is an example of an article URL:
https://www.forbes.com/sites/alexkonrad/2016/01/29/new-ibm-watson-chief-david-kenny-talks-his-plans-for-ai-as-a-service-and-the-weather-company-sale
Figure 3-48 Watson Author Finder application
The author name is retrieved from the Natural Language Understanding service (Figure 3-49).
Figure 3-49 Watson Author Finder returned results
3.4 Exercise review
During this exercise, you accomplished the following goals:
Created Hello World Express Application that includes two routes handling the URIs GET /, and POST /author. You should now understand the basics of Express Framework.
Sent the index.html page to the caller of the GET URI. You should now know how to use Express to send an HTML page to the user in response to a route.
Learned how to integrate a Node.js application with Watson Natural Language Understanding service.
Organized the code into routes, views, and services. By following the steps, you should now know about preferred practices for organizing Express applications in Node.js.
 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.238.31