“The only way to learn a new programming language is by writing programs in it. The first program to write is the same for all languages: Print the words ‘hello, world’.”
So started the introduction to the book The C Programming Language by Brian Kernighan and Dennis Ritchie back in 1978. Since then many a programmer learning a new language has heeded those words of wisdom by trying to write their first program to put up those immortal words on their computer screens. Even the Whitehouse is now in on the game.
You can find a list of how to write “hello, world” in pretty much any language you have ever heard of (as well as some you probably haven’t) here. The idea of writing such a simple program is not so much that it will teach you anything about the language syntax but it will teach you how to get to grips with the environment that the code (whether compiled or interpreted) runs in. Back in 1978 when C ran under Unix on hardware like Digital Equipment Corporation’s PDP-11 the environment was a relatively simple affair consisting of a processor, some storage and rudimentary cathode ray terminal (CRT). Then the ‘environment’ amounted to locating the compiler, making sure the right library was provided to the program and figuring out the options to run the compiler and the binary files output. Today things are a bit more complicated which is why the basic premise of getting the most simple program possible (i.e. writing ‘hello, world’ to a screen) is still very relevant as a way of learning the environment.
All of this is by way of an introduction to how to get ‘hello, world’ to work in the IBM Bluemix Platform as a Service (PaaS) environment. In case you haven’t heard, IBM Bluemix is an open source platform based on Cloud Foundry that provides developers with a complete set of DevOps tools to develop, deploy and maintain web and mobile applications in the cloud with minimal hassle. Bluemix-hosted applications have access to the capabilities of the underlying cloud infrastructure to support the type of non-functional requirements (performance, availability, security etc) that are needed to support enterprise applications. Bluemix also provides a rich set of services to extend your applications with capabilities like analytics, social, internet of things and even IBM Watson cognitive services. The Bluemix platform frees developers and organizations from worrying about infrastructure-related plumbing details and focus on what matters to their organizations – business scenarios that drive better value for their customers.
Step 1: Sign Up for a Free Bluemix Trial
You can sign up for a free Bluemix trial (and get an an IBM ID if you don’t have one) here. You’ll need to do this before you do anything else. The remainder of this tutorial assumes you have Bluemix running and you are logged into your account.
Step 2: Download the Cloud Foundry Command Line Interface
You can write code and get it up and running in numerous ways in Bluemix including within Bluemix itself, using Eclipse tools or with the Cloud Foundry command line interface (CLI). As this example uses the latter you’ll need to ensure you have the CLI downloaded on your computer. To do that follow the instructions here.
Step 3: Download the Example Code
You can download the code for this example from my GitHub here. Thanks to Carl Osipov over at Clouds with Carl for this code. Once you have downloaded the zip file unpack it into a convenient folder. You will see there are three files (plus a readme).
- package.json – which tells Bluemix it needs a Node.js runtime.
- manifest.yml – this file is used when you deploy your code to Bluemix using the command line interface. It contains the values that you would otherwise have to type on the command line when you ‘push’ your code to Bluemix. I suggest you edit this and change the ‘host’ parameter to something unique to you (e.g. change my name to yours).
Step 4: Deploy and Run the Code
Because all your code and the instructions for deploying it are contained in the three files just downloaded deploying into Bluemix is simplicity itself. Do the following:
- Open a command a Command Prompt window.
- Change to the directory that you unpacked the source code into by typing: cd your_directory.
- Connect to Bluemix by typing: cf api https://api.ng.bluemix.net.
- Login to Bluemix with your IBM ID credentials: cf login -u user-id -o password -s dev. Here dev is the Bluemix space you want to use (‘dev’ by default).
- Deploy your app to Bluemix by typing: cf push.
That’s it! It will take a while to upload, install and start the code and you will receive a notification when it’s done. Once you get that response back on the command line you can switch to your Bluemix console and should see this.
To show the program is working you can either click on the ‘Open URL’ widget (the square with the right pointing arrow in the hello-world-node-js application) or type the URL: ‘hello-world-node-js-your-name.mybluemix.net’ into a browser window (your-name is whatever you set ‘host’ to in the manifest file). The words ‘hello, world’ will magically appear in the browser. Congratulations you have written and deployed your first Bluemix app. Pour yourself a fresh cup of coffee and bask in your new found glory.
If you live in the UK and would like to learn more about the IBM Bluemix innovation platform then sign up for this free event in London at the Rainmaking Loft on Thursday 25th June 2015 here.