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]<code>var app = express()
var appEnv = cfenv.getAppEnv()

app.listen(appEnv.port, appEnv.bind, function() {
util.log("server starting on " + appEnv.url)
})
</code>[/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
December 12, 2018

Deploying to IBM Cloud Private 3.1 with IBM Cloud Developer Tools CLI

IBM Cloud Developer Tools CLI version 2.1.12 adds deployment support for IBM Cloud Private 3.1.

Continue reading

December 10, 2018

An Introduction to PostgreSQL’s hstore

One of the highlights of PostgreSQL is its versatility, especially when you need a flexible data model. In this post, we'll explore hstore, PostgreSQL's simple key-value store, and take a look at how it works using a catalog of books.

Continue reading

December 7, 2018

Highly Available Applications with IBM Cloud Foundry

To properly deploy an application in a cloud environment and ensure maximum responsiveness, your app needs to be deployed in a certain (and easy) way that maximizes the chance of an instance always being ready to respond to a user request. This article will explain how to deploy your Cloud Foundry applications in the IBM Cloud such that you reach your target application availability.

Continue reading