NOTE: Production deployment to IBM Cloud is a much bigger topic with manypossible options, refer to“”for the details.

Make sure you have:

  • an account on IBM Cloud. If not, you cansign up here.
  • installed

Preparing your application

We will be using thefrom the loopback-next repositoryas a basis for the instruction.

You can quickly clone the “todo” example app by running the command:

Then you can replace the default memory-based connector of the app with aCloudant connector, so data is persisted.

  • Go to the, select under All Categories > Databases.
  • Name your Cloudant service name as myCloudant. Keep the defaults for regionand resource group. Select “Use both legacy credentials and IAM” as theavailable authentication methods
  • Click Create.

Step 2: Creating a database named todo.

  • Click on myCloudant under Services.
  • Click Launch Cloudant Dashboard.

  • In the Cloudant dashboard, click Create Database at the top of the page andname it as todo.

create database

Update db.datasource.json to use the Cloudant connector. The value for theurl property is just a placeholder and does not need to have the correctcredential because we will be binding the app with the Cloudant service onceit’s pushed to IBM Cloud.

  1. {
  2. "name": "db",
  3. "connector": "cloudant",
  4. "database": "todo",
  5. "modelIndex": ""
  6. }

Install the loopback-connector-cloudant package.

Step 4: Updating the application

  • We will use the cfenv module to simplify some of the Cloud Foundry relatedoperations. Install cfenv in the project directory.
  1. $ npm i cfenv
  • Update the src/index.ts file to the following to enable service binding.Add the 3 snippets as indicated below:

If you make more changes to the application after this point, remember to run npm run build to transpile the code before deploying.

  • (Optional) At project root, create a file called .cfignore with thefollowing content:
  1. node_modules/
  2. .git

This step is optional, however, dependencies will be installed duringdeployment and thus node_modules will be generated. It makes the upload ofnode_modules reductant and time consuming.

  • Use cf login command to login.

If you’re using a federated user id, you can use the —sso option.

After you’ve been successfully logged in, you’ll see the CF API endpoint.

  • After logging in, you can run this command:
  1. cf push <<your-app-name>>

The app name in the command is the Cloud Foundry application that will showup in the IBM Cloud dashboard.

Step 6: Binding the Cloudant service to your application

  • Go to the IBM Cloud dashboard ().
  • Under Cloud Foundry Applications, you should see your application name.Click on it.
  • In the “Overview” tab, go to Connections > Create connection.
  • Select myCloudant service.
  • After the binding is done, you should see it from the Overview page.
  • You will be asked to restart your application.
  • Click Visit App URL to get the URL of your application. It will then bringyou to the API explorer for testing your endpoints.