New Relic performance monitoring for Node.js apps

Share this post:

The SDK for Node.js buildpack now contains better integration with the New Relic service in Bluemix.

When an app is bound to an instance of the New Relic service, the buildpack recognizes this based on the VCAP_SERVICES environment variable. It will then set the NEW_RELIC_APP_NAME and NEW_RELIC_LICENSE_KEY environment variables, which are recognized by the New Relic agent, for you. If you manually set these environment variables the buildpack will not override them.

Follow the steps below and you’ll be monitoring an app in no time!

Create the app

    1. Change to an empty directory and copy the following code into a file named package.json. This adds a dependency on the New Relic agent’s npm module.
          "name": "myapp",
          "version": "0.0.1",
          "private": true,
          "scripts": {
              "start": "node app.js"
          "dependencies": {
              "express": "4.13.x",
              "cfenv": "1.0.x",
              <b>"newrelic": "1.30.3"</b>
          "engines": {
              "node": "4.x"


    1. Then copy the following code into a file named app.json. This is a simple Express-based app. Notice how the first thing we do is load the newrelic module.
      var express = require('express');
      var cfenv = require('cfenv');
      var app = express();
      var appEnv = cfenv.getAppEnv();
      app.get('/', function (req, res) {
        res.send('Hello World');
      app.listen(appEnv.port, '', function() {
        console.log("server starting on " + appEnv.url);


  1. Optionally use environment variables or a newrelic.js file in the root of the application to change the default agent configuration options.
    exports.config = {
      logging: {
        level: 'trace',
        filepath: 'stdout'


    See config.default.js for all the configuration options.

  2. Finally, push your app to Bluemix.
    $ cf push &lt;app name&gt;
    $ cf create-service newrelic standard &lt;service instance name&gt;
    $ cf bind-service &lt;app name&gt; &lt;service instance name&gt;
    $ cf restage &lt;app name&gt;

Monitor the app

Wait a few minutes after your app starts for the data it generates to be reported, then open the New Relic Dashboard from within the Bluemix UI. From here you will automatically be logged in to the New Relic UI.

In the New Relic UI click on your application and you will be able to see your metrics like the web transaction time.


For a good summary of what the different metrics are see A Quick Guide to Getting Started with New Relic.

Add Comment
No Comments

Leave a Reply

Your email address will not be published.Required fields are marked *

More How-tos stories

A predictive Machine Learning model from Build to Retrain

This post is an excerpt from our solution tutorial that walks you through the process of building a predictive machine learning model, deploying it as an API to be used in applications, testing the model and retraining the model with feedback data. All of this happening in an integrated and unified self-service experience on IBM Cloud.

Continue reading

How to organize users, teams and applications in IBM Cloud

Learn how to organize your project with multiple deployment environments

Continue reading

How to build a cloud native app in 30 minutes

I’m one of the IBM Cloud App Service architects and have been involved in leading the team in the engineering and delivery of this tool for accelerating development of cloud native apps. After giving an overview of app architecture and stating the game plan,  I’ll take you through video demos of creating two microservices and an iOS […]

Continue reading