Skip to main content

Install the Node.js agent

There are several ways to install the agent depending on your situation, but generally, this is the process:

  1. Get the Node.js agent from npm.

  2. Set authentication keys .

  3. Add a command to the package.json file to enable your application to run with the agent.

  4. Run your application with the agent.

    For Node LTS 18.19.0 and later, use the --import command to run the agent.

    node --import @contrast/agent app-main.js [app arguments]

    For Node LTS versions greater than or equal to 16.17.0 and less than 18.19.0, use --loader to start the application.

    node --loader @contrast/agent app-main.js [app arguments]

    For Node LTS versions less than 16.17.0 use the legacy method for starting the application. This is also applicable to applications not using the ESM syntax.

    node -r @contrast/agent app-main.js [app arguments]
  5. Use your application as you normally would and verify that Contrast sees the application.

To avoid errors, follow these specific instructions depending on how your application is deployed: