The Node.js agent is publicly available on the npm repository and on GitHub.
Sugerencia
Using Docker? See Install the Node.js agent in Docker.
Prerequisites
Check these requirements before you start.
Requirement | Details |
|---|---|
New Relic account | You need a New Relic account and your . Have it ready before you begin. |
Node.js version | See Node.js agent compatibility and requirements for supported Node.js versions. |
Install the agent
Install the agent package in your application directory:
$npm install newrelicImportante
If you use Next.js, refer to the Next.js hybrid agent instrumentation guide.
Then copy the default configuration file from the package into the root of your application:
$cp node_modules/newrelic/newrelic.js .Configure the agent
Open newrelic.js in the root of your application. The only two settings you must change before going live:
Set
license_keyto your .Set
app_nameto a meaningful name for your application.exports.config = {app_name: ['Your Application Name'],license_key: 'YOUR_LICENSE_KEY',// ...}You can also set these via environment variables instead of editing the file:
bash$NEW_RELIC_APP_NAME="Your Application Name"$NEW_RELIC_LICENSE_KEY="YOUR_LICENSE_KEY"
Start the agent
Load the agent before any other require statements by adding -r newrelic to your startup command:
$node -r newrelic ./your-app.jsIf your application uses ESM, add the --import newrelic/esm-loader.mjs option:
$node --import newrelic/esm-loader.mjs -r newrelic ./your-app.jsFor a Next.js app, load our agent via NODE_OPTIONS='-r newrelic' next start.
If you're using Nest.js and the nest start command to start the application, modify its startup binary to load the New Relic agent: nest start --exec 'node -r newrelic'. Here is an example Nest.js application.
Verify data is flowing
If your agent version is 14.9.0 or above, you can run this command to validate your configuration:
$npx newrelic validate-config --config-file ./newrelic.jsSend at least two requests to your application.
Wait 2–3 minutes, then open one.newrelic.com > APM and look for your app by name.
Sugerencia
App not appearing? See Troubleshooting your Node.js installation.
Related articles
- Node.js agent compatibility and requirements — Supported Node.js versions and frameworks.
- Node.js agent configuration — All available configuration settings.
- Install in Docker — Container-specific installation steps.
- Update the Node.js agent — How to upgrade to a newer version.