Install Node.js agent with npm


If you are already using the Node.js agent, you should update the Contrast Node.js agent with this method since auto-update for the Node.js agent is no longer supported. 

To install the agent with npm:

  1. Find the API Key. The API key provided by Contrast Security is required for the agent to function.

  2. Install the latest LTS (Long Term Support) version of Node.js.

  3. To install from npm using the command line (run from the app root directory):

    npm install @contrast/agent

    If you use yarn, use an alternate command to install the agent:

    yarn add @contrast/agent
  4. Configure the agent using YAML-based configuration and the agent-specific configuration for Node.js.

  5. Add this script to your application's package.json file:

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

    npm run contrast

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

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

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