Community

Using the node.js cfenv package to make your life easier

Share this post:

I’ve just put together a little Bluemix application for node.js – bluemix-service-switcher – which shows how to access service information using the cfenv package.

This sample, and the cfenv package, should also work fine on any Cloud Foundry-based PaaS.

cfenv provides a number of functions to deal with the VCAP_SERVICES and VCAP_APPLICATION environment variables.

You will never have to JSON.parse() them again!

Almost every server I write uses the following little snippet to start the server:

<code>var app    = express()
var appEnv = cfenv.getAppEnv()

...

app.listen(appEnv.port, appEnv.bind,  function() {
  util.log("server starting on " + appEnv.url)
})
</code>

This will start your server on the right port, bind to right address, and print the url of the server when it’s started.

cfenv also works when you run locally, on your development machine, and provides appropriate default values when running in that environment.

The service-switcher application makes use of cfenv‘s functions to show how easy it is to access your bound services, and for your app be flexible about the services it binds to.

More stories

Welcome to the New and Improved IBM Cloud Catalog

We are excited to announce that the IBM Cloud Catalog has recently undergone a bit of a makeover. With simplified categories, featured services, and an improved UX design, users can discover IBM Cloud offerings without the need to understand IBM-specific terminology or branding.

Continue reading

Part II: Wimbledon Facebook Bot on IBM Cloud

In the second in a series of posts about how IBM iX designed, developed, and delivered the Facebook Messenger Bot available at Wimbledon 2018, we focus on the broadcast integration within Facebook and how we persisted user preferences using IBM Cloudant and Compose Redis.

Continue reading

Part I: Wimbledon Facebook Bot on IBM Cloud

Integration with the Facebook platform: This is the first in a series of posts that will detail how IBM iX designed, developed, and delivered the Facebook Messenger Bot available at the The Championships, Wimbledon 2018.

Continue reading