How to Add the Contrast Node Agent to a Node.js Application Hosted in IISNode

  • Updated

Objective

This article provides a guide on integrating the Contrast Node agent into a Node.js application hosted in IISNode.

Process

  1. Install the Contrast Node agent
    Run the following command from your application's root directory to install the latest version of the agent:
    npm install @contrast/agent
  2. Configure the Node agent
    Set up the Node agent using either the CONTRAST environment variables or a contrast_security.yaml file in the application's root directory. For more details, use the Contrast agent configuration editor to verify, validate, and export Contrast properties.
  3. Update the web.config file
    Add the following configuration to your web.config to set the NODE_OPTIONS environment variable:
    <configuration>  
    <appSettings>
    <add key="NODE_OPTIONS" value="--import @contrast/agent" />
    </appSettings>
    </configuration>
  4. Restart the application in IIS
    After updating the configuration, restart your application in IIS to apply the changes.
  5. Test the application
    Exercise your application by navigating through it.
    A 500 Internal Server Error may briefly appear, but it should resolve after a browser refresh. This is due to the initial startup overhead introduced by the Contrast agent during the rewrite process.

 

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request