Compute Services

Building IBM Cloud Functions with TypeScript

Share this post:

Building IBM Cloud Functions with Typescript starter kit

When learning new technology, it’s often helpful to begin by exploring a starter kit. Beyond the proverbial “Hello World,” starter kits are pre-built to focus on a core technology and support libraries and packaging. This helps bring everything together into an opinionated and functioning example.

There are, however, so many development options that no single starter kit will satisfy everyone. And after not finding one for Cloud Functions and Typescript, I’ve created my own. Consider using the starter kit for your next project for the following reasons:

  1. Many serverless examples use native Javascript, but as projects grow in size, better type checking and code modularity are needed. This is why Typescript was chosen for the starter. Consider the Cloud Functions entry point main(params). Is the params.id property a string or a number? With Typescript, you can make this explicit and leverage ES6 syntactic sugar and range of additional programming constructs.
  2. Unit testing might be new to you. Typescript might also be new to you. And if both are new to you, that’s OK! Provided in the starter are examples of testing Cloud Functions using Mocha. Tests are executed using npm run test, which uses the ts-node utility to quickly test without having to build.
  3. The starter kit uses webpack to organize code. By using webpack, you can write multiple actions that are contained in a single project. And any external dependencies used by your actions will be packaged for you automatically. A working webpack.config.js is provided and sample actions declare (global).main = main; to make them compatible. Additionally, the starter will exclude any natively supported NPM modules from the final bundle.
  4. Finally, being declarative about deployment doesn’t mean writing complicated shell scripts—simply use wskdeploy. A sample manifest.yaml has been structured to work with webpack, and it deploys two APIs. See the wskdeploy documentation for more deployment options.

Ready to use the starter? Head over to GitHub and download the code.

IBM Offering Manager

More Compute Services stories
September 13, 2018

How KONE Uses Data Analytics with Event-Driven Compute

KONE, a global leader in the elevator and escalator industry, is investing in IBM's Cloud and Internet of Things technologies to power a data-analytics and predictive-maintenance solution for city infrastructure.

Continue reading

August 24, 2018

Single Service Mesh with Istio Against Multiple Hybrid Clusters

Istio provides a complete solution to connect, manage, and secure microservices and supports multiple clusters by providing a central control plane. We're going to show you how to use one Istio control plane to control both an IBM Cloud Private cluster and an IBM Kubernetes Services cluster.

Continue reading

August 20, 2018

New Pricing for IBM Cloud Kubernetes Load Balancer

Effective September 20, 2018, the pricing for the IBM Cloud Kubernetes load balancer will be changing.

Continue reading