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

Create Dynamic Rules for Access Groups

Users or admins can now dynamically create access rules on the IBM Cloud Platform based on identity information shared from their Enterprise Identity Provider.

Continue reading

Configuring IBM Cloud App ID From the Toolchain

Learn how to configure the IBM Cloud App ID from a toolchain as part of continuous delivery process. This post gives some background and the script we use.

Continue reading

Part III: Wimbledon Facebook Bot on IBM Cloud

Delivering at scale: In the final part of the series, we discuss integrations with on-site systems at the All England Club and how we used Multi-Region within IBM Cloud to ensure scale and availability.

Continue reading