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

99.95% availability. Balancing release velocity and reliability

Availability and reliability are rarely at the front of developers minds when delivering new applications on Bluemix. The ease and speed of creating and deploying new features is very seductive.

Continue reading

Deploying to IBM Cloud private with IBM Cloud Developer Tools CLI

IBM Cloud private is an application platform for developing and managing on-premises, containerized applications. It is an integrated environment for managing containers that includes the container orchestrator Kubernetes, a private image repository, a management console, and monitoring frameworks.

Continue reading

Quickly Develop, Build, and Deploy Applications on IBM Cloud with DevOps services – Part 2

In this post, we'll talk about how you can create a DevOps toolchain in Bluemix using Bluemix Continuous Delivery if you've already built and deployed an application.

Continue reading