Command line arguments for Node.js

To pass configuration options to the 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:

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

will pass appArg0 foo and appArg1 bar directly to the application.

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

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

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 as the script argument, followed by the name of the application's entry point file and any configuration flags, as shown above.

When the agent is installed, a symlink is created, <app-dir>/node_modules/.bin/node-contrast, which points to the file <app-dir>/node_modules/node_contrast/cli.js. You can use either of these as the script argument when starting the application this way.

For example:

Without the Contrast agent, you start your application like this:

node --title=MyWebsite --stack-trace-limit=25 ./index.js --env development

To run the application with the same Node.js flags and the Contrast agent, you could use either of these commands:

node --title=MyWebsite --stack-trace-limit=25 ./node_modules/.bin/node-contrast ./index.js -- --env development
node --title=MyWebsite --stack-trace-limit=25 ./node_modules/node_contrast/cli.js ./index.js -- --env development