Working with a service broker and the Node.js starter app
You can bind your applications in Cloud Foundry Enterprise Environment to services that exist outside of your environment by using the Node.js getting started application.
Service brokers advertise a catalog of service offerings and plans to the marketplace, and act on requests from the marketplace for provisioning, binding, unbinding, and de-provisioning services. Cloud Foundry Enterprise Environment provides a mechanism for you to register a service broker and use services that might not be provided by or available in your cloud environment.
This example uses the open service broker starter pack that Cloud Foundry Enterprise Environment provides. It guides you through the process to prepare and deploy your application, register a service broker, create a Mongo® DB service instance, and connect to the Mongo database by using the Node.js getting started application.
Before you begin
Required user type or access level: For IBM Cloud Private: Cluster administrator, for Cloud Foundry Enterprise Environment: space manager
You need the following tools:
Step 1: Deploy a service broker in your IBM Cloud Private environment
See Implementing Open Service Broker (OSB) database in Cloud Foundry Enterprise Environment to deploy the open service broker starter pack in IBM Cloud Private environment.
Step 2: Register a service broker
You can use the Cloud Foundry cf create-service-broker command to register a service broker. Replace ICP-IP and NODE-PORT-NUMBER.
$ cf create-service-broker icp-service-broker admin password https://ICP-IP:NODE-PORT-NUMBER
Step 3: Make service offerings and plans public
Use the Cloud Foundry cf service-access command to see the access settings on the services in the marketplace.
$ cf service-access
Use the Cloud Foundry cf enable-service-access command to enable access on the Mongo DB service.
$ cf enable-service-access mongodb-service
Step 4: Create a service instance
Create a service instance by using the cf create-service command.
$ cf create-service mongodb-service default my-mongodb-service
Step 5: Clone the sample app
Clone the sample app GitHub repo.
git clone https://github.com/IBM-Bluemix/get-started-node
Step 6: Run the app locally by using the command line
On the command line, change the directory to where the sample app is located.
cd get-started-node
Install the dependencies that are listed in the package.json file to run the app locally.
npm install
Run the app.
npm start
You can view your app at http://localhost:3000.
Tip: Use nodemon for automatic restarting of the application with file changes.
Step 7: Prepare the app for deployment
To deploy your application to IBM Cloud Private, it can be helpful to set up a manifest.yml file. The manifest.yml file includes basic information about your app, such as the name, how much memory to allocate for each instance,
and the route. You can find a sample manifest.yml file in the get-started-node directory.
Open the manifest.yml file, and change the name from GetStartedNode to your app name, app_name.
applications:
name: GetStartedNode
random-route: true
memory: 128M
Copy
Tip: In this manifest.yml file, random-route: true generates a random route for your app to prevent your route from colliding with others. If you choose to, you can replace random-route: true with host: myChosenHostName, and supply a host name of your choice.
Step 8: Deploy to Cloud Foundry Enterprise Environment
Deploy your app to your Cloud Foundry Enterprise Environment by using your Cloud Foundry Enterprise Environment URL.
cf api
Log in to your Cloud Foundry Enterprise Environment account.
cf login
From within the get-started-node directory, push your application to IBM Cloud Private.
cf push
Deploying your application can take a few minutes. When deployment completes, you see a message that your app is running. View your app at the URL that is listed in the output of the push command, or view both the app deployment status and the URL by running the following command:
cf apps
Tip: You can troubleshoot errors in the deployment process by using the cf logs --recent command.
Step 9: Use Mongo DB MongoDB service
Bind the Mongo DB service instance to the getting started application.
cf bind-service GetStartedNode my-mongodb-service
Restage the application.
cf restage GetStartedNode
Step 10: Confirm
Refresh your browser view at http://localhost. Any names that you enter in the app are added to the database. Make note of the external node port number.