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
May 7, 2019

We’ve Moved! The IBM Cloud Blog Has a New URL

In an effort better integrate the IBM Cloud Blog with the IBM Cloud web experience, we have migrated the blog to a new URL: www.ibm.com/cloud/blog.

Continue reading

May 6, 2019

Use IBM Cloud Certificate Manager to Obtain Let’s Encrypt TLS Certificates for Your Public Domains

IBM Cloud Certificate Manager now lets you obtain TLS certificates signed by Let’s Encrypt. Let’s Encrypt is an automated, ACME-protocol-based CA that issues free certificates valid for 90 days.

Continue reading

May 6, 2019

Are You Ready for SAP S/4HANA Running on Cloud?

Our clients tell us SAP applications are central to their success and strategy for cloud, with a deadline to refresh the business processes and move to SAP S/4HANA by 2025. Now is the time to assess, plan and execute the journey to cloud and SAP S/4HANA

Continue reading