---
title: Install the Node.js agent
source: https://docs.newrelic.com/docs/apm/agents/nodejs-agent/installation-configuration/install-nodejs-agent
---

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 JP if you're in the JP region) 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!](https://docs.newrelic.com/docs/accounts/accounts-billing/new-relic-one-pricing-billing/new-relic-one-pricing-billing/#how-pricing-works))

[Get an account](https://newrelic.com/signup)

[Start agent install](https://one.newrelic.com/marketplace/install-data-source?state=ccfdfbe4-d603-7a77-19ff-ba44f5de7c82)

[EU guided install](https://one.eu.newrelic.com/marketplace/install-data-source?state=ccfdfbe4-d603-7a77-19ff-ba44f5de7c82)

[JP guided install](https://onenr.io/02wdX0MPEwE)

Our Node.js agent is publicly available on the [Node Package Manager (npm) repository](https://npmjs.org/package/newrelic) as well as on [GitHub](https://github.com/newrelic/node-newrelic).

## Install the Node.js agent [#installing]

> #### ⚠️ IMPORTANT
>
> If you're using the agent in a Docker container, [install the agent in each container](https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/install-new-relic-nodejs-agent-docker).

To install the Node.js agent:

1.  Create a New Relic account. Don't have one? [Sign up for free!](https://newrelic.com/signup) No credit card required.

2.  Ensure you meet the [system requirements](https://docs.newrelic.com/docs/agents/nodejs-agent/getting-started/compatibility-requirements-nodejs-agent). In particular, make sure you use a supported Node.js version.

3.  Use the command `npm install newrelic` for each application you want to monitor.

    > #### ⚠️ IMPORTANT
    >
    > If you use Apollo Server modules, refer to the [Apollo Server plugin documentation](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/extend-your-instrumentation/apollo-server-plugin-nodejs/) for installation details.
    >
    > If you use Next.js, refer to the [Next.js hybrid agent instrumentation guide](https://docs.newrelic.com/docs/apm/agents/nodejs-agent/extend-your-instrumentation/nextjs-instrumentation/).

4.  From `node_modules/newrelic`, copy `newrelic.js` into the root directory of your app.

5.  Configure agent via the `newrelic.js` file or via [environment variable](https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/nodejs-agent-configuration#environment):
    -   Customize the `license_key` setting with license key.
    -   Customize the [`app_name`](https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/nodejs-agent-configuration#app_name) setting with one or more [meaningful app names](https://docs.newrelic.com/docs/apm/new-relic-apm/installation-and-configuration/naming-your-application).

6.  Add `-r newrelic` to your app's startup script. For example, if your application's entry point is `./dist/server.js` then you would use the require flag like so:

    ```bash
    node -r newrelic ./dist/server.js
    ```

    An example Docker command:

    ```dockerfile
    CMD ["node", "-r", "newrelic", "server.js"]
    ```

    > #### ⚠️ IMPORTANT
    >
    > For a Next.js app load our agent via `NODE_OPTIONS`:
    >
    > ```dockerfile
    > CMD ["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](https://github.com/newrelic/newrelic-node-examples/tree/main/nestjs)

    More info about the [Node.js command line option `-r` here](https://nodejs.org/api/cli.html#-r---require-module).

    > #### ⚠️ IMPORTANT
    >
    > If you are unable to use the `-r` require flag, you can also use `require('newrelic')` as the first line of your app's main module. However, if you are using [Babel](https://babeljs.io/docs/en/index.html) or a similar transpiler, `require('newrelic')` will cause instrumentation issues.
    >
    > ```js
    > // load the agent
    > const newrelic = require('newrelic');
    >
    > // load other packages
    > const expressModule = require('express');
    > ```

7.  Optional: For additional [Node.js runtime-level statistics](https://docs.newrelic.com/docs/agents/nodejs-agent/supported-features/node-vms-statistics-page), ensure the [`@newrelic/native-metrics` package is installed](https://docs.newrelic.com/docs/agents/nodejs-agent/supported-features/node-vm-measurements).

8.  Generate some traffic, then wait a few minutes for data to appear in the [APM UI](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/apm-overview-page).

You can further [customize your agent behavior](https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/nodejs-agent-configuration) via `newrelic.js` or an environment variable. To keep the agent configuration separate from your app, edit the [`NEW_RELIC_HOME` environmental variable](https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/nodejs-agent-configuration#home).

For more information, see our [API doc](https://newrelic.github.io/node-newrelic/API.html).

## View logs for your APM and infrastructure data [#logs-context]

You can also bring your logs and application's data together to make troubleshooting easier and faster. With [logs in context](https://docs.newrelic.com/docs/logs/logs-context/configure-logs-context-nodejs/), 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](https://docs.newrelic.com/docs/logs/forward-logs/forward-your-logs-using-infrastructure-agent/), such as Kubernetes clusters. No need to switch to another UI page.

## Keep your Node.js agent up-to-date [#upgrading]

To ensure that you have the most up-to-date version of New Relic, refer to the [Node.js release notes](https://docs.newrelic.com/docs/release-notes/agent-release-notes/nodejs-release-notes). When applicable, the release notes include a download link with instructions on how to [update the Node.js agent](https://docs.newrelic.com/docs/agents/nodejs-agent/installation-configuration/upgrade-nodejs-agent).

## Troubleshooting [#troubleshoot]

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](https://docs.newrelic.com/docs/agents/nodejs-agent/troubleshooting/troubleshooting-your-nodejs-installation).
