Install Node.js agent
Using the Agent Wizard is the simplest way to deploy a new agent. Additional methods are also available, including in a container, in a pipeline, or on a platform.
Before you begin a Node.js agent installation
Make sure you have everything you need before you start.
The agent will need to be able to reach your Contrast instance. It can be a local/on-premise instance or a hosted instance. A proxy can be configured if the environment has limited network access.
It must use supported technologies and system requirements.
Understand the order of precedence.
You will also need access to a command line interface (with a chosen directory for downloading the agent) and your organization's instance of Contrast
Start the Agent Wizard
To open the Agent Wizard:
In Northstar: From the left navigation, select Administration > Agent management, then select Add agent at the top of the view.
In Contrast: Use one of the following options:
From the header, select Add New, and then select the Application card.
From the header, select Administration > Agent Management, and then select Add agent at the top of the view.
Select the Node.js agent
In the Agent Wizard:
Under Select an installation method, select Language-specific.
Under Select a language, select Node.
Under Select Operating System, select Linux or macOS or Windows.
Install the agent
Under Select application deployment method, select Install manually.
Install the latest version of the agent from
npmby running the following command from the application's root directory:npm install @contrast/agent
Alternatively, you can also use
yarnto install the agent:yarn add @contrast/agentAdd the following command to the scripts section of your application's
package.jsonfile:"scripts": { "contrast": "node --import @contrast/agent app-main.js [app arguments] "start": ..., "test": ... }The
--importflag works for CommonJS and ESM applications. The agent does not accept--loaderon Node.js 20 and later.Follow the instructions in the wizard to configure the Node agent.
The agent requires a connection token or an API configuration to communicate with Contrast. You can use a connection token (recommended) or you can download the configuration as a YAML file.
Alternatively, set the configuration with a YAML file, using the YAML template. Put
contrast_security.yamlin the folder you start the application from, or in/etc/contrast/node/.Run your application with the agent:
npm run contrast
You can change this npm script to include, other runtime configurations such as an alternate configuration file location.
Verify the agent deployment
Interact with your application as you normally would. For example, interact with your application's web interface or send API commands.
In the Agent Wizard, select View agent activity to verify that your agent appears in the agents list.
Verify that you see the name of your application in the applications list.
In Northstar, select Applications from the left navigation.
In Contrast, select Applications from the header.
Verify that you see the name of your local server in the servers list.
In Northstar, select Servers from the left navigation.
In Contrast, select Servers from the header.