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. Install the Node.js agent from npm by running the npm install @contrast/agent command in the application's root directory.

  2. Set authentication keys.

  3. Add a command to the package.json file to enable your application to run with the agent. Depending on the method of installation, one of the following commands can be added to the package.json file.

    • 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]
  4. Use your application as you normally would and verify that Contrast sees the application.

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