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
February 21, 2019

A How-To for Migrating Elasticsearch to IBM Cloud Databases for Elasticsearch

If you’re moving your data over to IBM Cloud Databases for Elasticsearch, you’ll need to take some steps to successfully migrate all of your data. In this post, we’ll show you how to securely migrate your data from Compose to Databases for Elasticsearch using your own object storage.

Continue reading

February 18, 2019

Build a Container Image Inside a Kubernetes Cluster and Push it to IBM Cloud Container Registry

We're going to show you how to build a source into a container image from a Dockerfile inside a Kubernetes cluster and push the image to IBM Cloud Container Registry with Google's Kaniko tool.

Continue reading

February 13, 2019

Simplify and Automate Deployments Using GitOps with IBM Multicloud Manager 3.1.2

Use Argo CD, a GitOps continuous delivery tool for Kubernetes, and IBM Multicloud Manager to achieve declarative and automated deployment of applications to multiple Kubernetes clusters.

Continue reading