To complete a basic Node.js agent installation, you can use our guided installation for an automated install, (choose EU if you're in the EU) or follow the instructions in this document. Either way, you need a New Relic account if you don't already have one. (It's free, forever!)
If you're using the agent in a Docker container, install the agent in each container.
To install the Node.js agent:
Create a New Relic account. Don't have one? Sign up for free! No credit card required.
Ensure you meet the system requirements. In particular, make sure you use a supported Node.js version.
Use the command
npm install newrelic --savefor each application you want to monitor.
newrelic.jsinto the root directory of your app.
Configure agent via the
newrelic.jsfile or via environment variable:
require('newrelic');as the first line of your app's main module.
If you are using Babel or a similar transpiler you can safeguard against any issues related to module load order by utilizing the Node.js command line option '-r' to preload the 'newrelic' module at application startup. For example, if your application's entry point is
./dist/server.js then you would use the require flag like so:
node -r newrelic ./dist/server.js
If you are unable to
require('newrelic'); as the first line of your app's main module and you are unable to use the require flag as above (e.g. asynchronously loading api keys from a remote location during application bootstrapping), you may also add stock instrumentation to an already loaded supported module by using
// module loaded before newrelicconst expressModule = require('express');// load the agentconst newrelic = require('newrelic');// instrument express after the agent has been loadednewrelic.instrumentLoadedModule('express', // the module's name, as a stringexpressModule // the module instance);
- Optional: For additional Node.js runtime-level statistics, ensure the
@newrelic/native-metricspackage is installed.
- Generate some traffic, then wait a few minutes for data to appear in the APM UI.
Did this doc help with your installation?
You can also bring your logs and application's data together to make troubleshooting easier and faster. With logs in context, you can see log messages related to your errors and traces directly in your app's UI. You can also see logs in context of your infrastructure data, such as Kubernetes clusters. No need to switch to another UI page.
To ensure that you have the most up-to-date version of New Relic, refer to the Node.js release notes. When applicable, the release notes include a download link with instructions on how to update the Node.js agent.
After you update the agent, generate some traffic and wait a few minutes. If no data appears in the New Relic UI, see the troubleshooting procedures.