TL;DR If you’re using NodeJS and want to monitor using NewRelic, follow these steps. Additionally if you want to do this on Heroku using the NewRelic account you added through the Heroku API, make sure your package.json has “newrelic” and your newrelic.js points to the NEW_RELIC_LICENSE_KEY environment variable.
Last Friday, I set up a NodeJS push notification server for my current project. Essentially it was mostly inspired by this excellent blog post, but I updated it to use the latest NPM packages and to support sending notifications to all of a user’s open sockets as well as cleaning up on disconnect. That’s another story for another time.
This blog post will cover how to get NodeJS monitoring with NewRelic on Heroku.
Some veterans may know that for a while, NewRelic didn’t support NodeJS. That has now changed.
All you really need to do is define your dependencies:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
npm install and add
require('newrelic'); to your
server.js (or whatever you named your NodeJS main file).
node_modules/newrelic into the root directory of your application. Open it up, and as the instructions say, add your licence key for NewRelic into this file. That said, for Heroku users who opted in for the free NewRelic account via Heroku, you want to do this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
So that you can point to the environment variable that Heroku set up for you when you added NewRelic to your account.
Thats it !
If you have any suggestions, contributions or issues, please feel free to leave a comment.