Command line arguments for the Node.js Agent

  • Updated
In v5.x+ of the Node.js agent, you must use YAML configuration and environment variables for your configuration. However, in the v4.x agents, it's possible to use command line arguments for some settings.

The v4.x Contrast Node.js agents have a help parameter that will list all the valid command line values:

Usage: node -r @contrast/agent app-main.js [agent arguments] -- [app arguments]
   -h, --help               output usage information
   -V, --version            output the version number
   -c, --configFile <path>  path to agent config file

To pass configuration options to the Node.js application being run with Contrast, use the --application.args flag, or append -- to the run command, followed by the arguments for the application.

For example, to pass appArg0 foo and appArg1 bar directly to the application, use:

npm run contrast -- --agent.logger.level debug -- --appArg0 foo --appArg1 bar 

For command line arguments, the Node.js documentation shows that scripts are executed like this:

node [options] [V8 options] [script.js] [--] [arguments];

For example, if you have added a "contrast" script to your application's package.json, use:

"scripts": {
    "contrast": "node -r @contrast/agent server.js --configFile=/home/contrast-user/contrast_agents_RHEL76/node/3.4.0/contrast_security.yaml",

The Contrast agent is a Node.js wrapper (runner) that invokes node to start the application. The agent doesn't pass any flags to the underlying Node.js executable, or provide the ability to do so with agent configuration options.

To pass command line flags to Node.js, you must invoke node explicitly with the agent within the scripts section of your application's package.json, followed by the name of the application's entry point file and any configuration flags, as shown above.

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request