page-brochureware.php

Getting Started with Node.js on IBM Cloud

Introduction

The following tutorial walks you through the steps to create, build, run locally and deploy a Node.js project. Use the IBM Cloud Developer Tools CLI on the command line or the web-based IBM Cloud App Service on the IBM Cloud dashboard. These tools enable you to generate a Node.js application on-demand, fully equipped with an Express server, integration with IBM Cloud Services, and deployment configurations for Cloud Foundry and IBM Container Service on IBM Cloud.


Using the CLI

The IBM Cloud Developer Tools CLI provides a command driven approach for creating, developing, and deploying a web project. It’s ideal for developers that would like to use command line control to develop end-to-end microservice applications.

  1. Install prerequisites

    Use the following curl command to install git, docker, kubectl, helm and IBM Cloud Developer Tools CLI.

    curl -sL https://ibm.biz/idt-installer | bash

  2. Create

    Use the bx dev create command from IBM Cloud Developer Tools CLI to generate a pre-configured starter that fits your application needs.

    • Note: You need to be logged into an IBM Cloud account to create a project. If you do not have an account already, you can register for a free account. Use the bx login command to login on the command line.

  3. Build

    Use the bx dev build command to build your application.

  4. Run locally

    Use the bx dev run command to run the application locally. You can test your application in a browser by going to localhost:3000.

  5. Deploy to IBM Cloud

    Use bx dev deploy to deploy to IBM Cloud as a Cloud Foundry application. To deploy to IBM Container Service in IBM Cloud using Kubernetes techniques, use bx dev deploy –target container.

    Check out our documentation for more information on setting up a Kubernetes cluster in IBM Cloud.

Using the App Service

IBM Cloud App Service is an online console that makes it easy to quickly create and manage applications, configure and attach services (such as databases, notifications, and Watson), and monitor and deploy apps. You can use the App Service to deploy to IBM Cloud as a Cloud Foundry application, to IBM Container Service or through a DevOps toolchain.

  1. Create

    1. From the Starter Kits page in the App Service, select a Starter Kit based on your chosen programming language. For example, for a Node.js application, go to Express.js Basic and click Select Starter Kit.
      • Note: You need to be logged into an IBM Cloud account to create a project. If you do not have an account already, you can register for a free account.
    2. Enter your project name.
    3. Enter a unique hostname. This hostname will be used for your project’s route.
      For example: my-express-project.mybluemix.net.
    4. Click Create Project. After your project is created, you have the option to deploy using a toolchain OR you can continue to build and deploy your project from the command line.
    5. If you choose to create a toolchain, click Deploy to Cloud in the Deploy your App panel. Select a deployment method. You can choose either:
      • Kubernetes Cluster, where you can provision a set of worker nodes, e.g. VMs, to deploy and manage highly available application containers. You can create a cluster or deploy to an existing cluster.
      • Cloud Foundry App, where you do not need to manage the underlying infrastructure.

      Click Create after configuring any options to create the toolchain.

    6. If you choose to continue with the CLI, download your project to your local machine, unzip it and cd into the root directory. You will need to install the prerequisites with the following curl command:

      curl -sL https://ibm.biz/idt-installer | bash

      Then continue with the build and deploy steps below.

  2. Build

    Use the bx dev build command to build your application.

  3. Deploy to IBM Cloud

    Use bx dev deploy to deploy to IBM Cloud as a Cloud Foundry application. To deploy to IBM Container Service in IBM Cloud using Kubernetes techniques, use bx dev deploy –target container.

    For more information on setting up a Kubernetes cluster in IBM Cloud go here.


Conclusion

This tutorial taught you how to create and deploy a project using two approaches: the IBM Cloud Developer Tools CLI and the IBM Cloud App Service.

For more information, check out Node.js @ IBM and take a look at the following tutorials: