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
October 17, 2018

Introduction: Build Messaging Solutions with Apache Kafka or Event Streams for IBM Cloud

This multi-part blog series is going to walk you through some of the key architectural considerations and steps for building messaging solutions with Apache Kafka or IBM Event Streams for IBM Cloud. This series will be helpful for developers, architects, and technology consultants who have a general understanding of Apache Kafka and are now looking toward getting deeper into evaluating and building messaging solutions.

Continue reading

October 15, 2018

A Quick Guide to Redis Lua Scripting

In this post, we'll introduce Lua scripting for Redis, making sure that all the commands work with IBM Cloud Databases for Redis.

Continue reading

October 15, 2018

Add Custom Domain and TLS Certificate to Your Secure Cloud App

Secure your cloud app end to end. Use a custom domain with TLS certificate for apps deployed on IBM Cloud Kubernetes Service.

Continue reading