Objective
This article provides a guide on integrating the Contrast Node agent into a Node.js application hosted in IISNode.
Process
-
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
-
Configure the Node agent
Set up the Node agent using either theCONTRASTenvironment variables or acontrast_security.yamlfile in the application's root directory. For more details, use the Contrast agent configuration editor to verify, validate, and export Contrast properties. -
Update the web.config file
Add the following configuration to yourweb.configto set theNODE_OPTIONSenvironment variable:
<configuration>
<appSettings>
<add key="NODE_OPTIONS" value="--import @contrast/agent" />
</appSettings>
</configuration> -
Restart the application in IIS
After updating the configuration, restart your application in IIS to apply the changes. -
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.