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:
main(params). Is the
params.idproperty a string or a number? With Typescript, you can make this explicit and leverage ES6 syntactic sugar and range of additional programming constructs.
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.
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.
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.