Skip to main content

Install Node.js agent manually

To install or update the agent manually:

  1. Install the latest version of the agent from npm by running this command from the application's root directory:

    npm install @contrast/agent

    Alternatively, if you use yarn, run this command to install the agent:

    yarn add @contrast/agent

    Note

    If you don't want to install optional dependencies included with the Node.js agent, append the --no-optional CLI flag to your install command or add optional=false to your NPMRC file.

  2. Set authentication keys with environment variables. Make sure your Node.js application has access to the environment variables at runtime.

    Alternatively, set the configuration with YAML configuration using this template. Make sure the contrast_security.yaml is in the applications root directory.

  3. Add this command to the scripts section of your application's package.json file:

    "scripts": {
        "contrast": "node -r @contrast/agent <app-main>.js",
        "start": ...,
        "test": ...
    }
    
  4. Run your application with the agent:

    npm run contrast

    Tip

    You can change this npm script to include, other runtime configurations such as an alternate configuration file location.

  5. Exercise your application by performing either manual or automated testing to ensure your application is functioning correctly with the agent installed.

  6. Verify that your server is registered in Contrast and reports an instance of your application.