Update the Node.js agent
The most reliable and effective way to automatically update the Contrast Node.js agent is to use the Node.js npm package manager to install and download the latest version available.
Because npm manages all dependencies for your Node.js application, it should already be available and part of your build environment. How frequently you update the Contrast Node.js agent and where you get updates depends on your organization’s preferences and your Contrast implementation: hosted (SaaS) or on-premises (EOP).
You can either update the agent automatically or manually.
Before you begin
Before you begin, you should have:
Some familiarity with DevOps practices and Node’s npm package manager.
Access to the npm repository for the Contrast agent.
Confirmed that your Node.js application runs properly without the Contrast Node.js agent.
Previously successfully installed the Contrast Node.js agent.
Defined a policy for how and when to update the agent, based on your change management policy and the environment where you deploy agents.
Important
Unless Contrast Support advises you to do so, do not use a version of the Contrast Node.js agent that is ahead of the version available from your Contrast instance.
Steps
You will install the Node.js agent from the npm public (or private) repository. Depending on your Contrast installation, you can use one or both sources to get the latest Contrast Node.js agent:
Hosted (SaaS) installations: You can get the latest version of the agent from npm. If your organization prefers to validate agents before using them, you can also use a private npm repository with approved versions only.
On-premises (EOP) installations: Many organizations that use on-premises installations do not immediately update core software or agents when Contrast releases new software. Public repositories (like npm) typically host new versions of the agent that are not designed or tested to work with older versions of Contrast. On-premises users should source agent updates from a private npm repository where you only store versions of the agent that match your on-premises Contrast installation.
Install the agent and use scripts for automatic updates using the best method for you:
Use
package.json
: This file specifies which dependencies will automatically resolve every time your Node.js application builds with artifacts from npm (public or private). Include the Contrast Node.js agent here to easily keep every new build of your application aligned with the latest version of the agent. For example:{ "name": "sample_application", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "start": "nodemon", "contrast": "node --import @contrast/agent index.js" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "express": "^4.17.1", "@contrast/agent": "latest", }, "devDependencies": { "nodemon": "^1.19.2" } }
Then use the
$ npm update
command whenever you build your application. This will automatically download, and add or update, the Contrast Node.js agent from npm to the Node.js application.Install and update manually using command line: For some organizations, the
package.json
file must be consistent across environments, or they do not plan to install the Contrast Node.js agent into all environments. In these cases, install the agent manually. You can manually update agents as part of a Node.js build process.Use this command to manually retrieve and add or update the Contrast Node.js agent from npm (public or private) to the Node.js application:
$ npm install @contrast/agent
To check whether the installation/update succeeded, run the following command and look for output similar to the following example:
❯ npm ls --all | grep contrast ├─┬ @contrast/agent@5.11.0 │ ├─┬ @contrast/agentify@1.28.0 │ │ ├── @contrast/common@1.22.0 │ │ ├─┬ @contrast/config@1.29.0 │ │ │ ├── @contrast/common@1.22.0 deduped │ │ ├─┬ @contrast/core@1.33.0 │ │ │ ├── @contrast/common@1.22.0 deduped │ │ │ ├── @contrast/find-package-json@1.2.0 deduped │ │ │ ├── @contrast/fn-inspect@4.2.0 deduped │ │ ├─┬ @contrast/deadzones@1.3.0 │ │ │ └── @contrast/common@1.22.0 deduped