Skip to main content

Install Node.js with IBM Cloud

  1. Install the latest LTS (Long Term Support) version of Node.js.

  2. To install from npm, run this command from the app root directory:

    npm install @contrast/agent

    Alternatively, if you use yarn, run this command to install the agent:

    yarn add @contrast/agent
  3. Configure the Node.js using a YAML configuration file to set the authentication keys and any application-specific configuration.

    You can use this sample contrast_security.yaml file, but replace <URL>, <UserName>, <APIKey> and <ServiceKey> with your values, and set <ServerName> to the name of the IBM cloud server to which this application will report. (This way you will be able to identify the server when you view it in Contrast.)

       url: <URL>
       user_name: <UserName>
       api_key: <APIKey>
       service_key: <ServiceKey>
       name: <ServerName>
  4. Copy your Contrast YAML file to your application's root directory or use environmental variables to set the required Contrast API credentials and configuration settings.

  5. Add this command to the "scripts": section of your application's package.json file:

    "ibmcloud-with-contrast": "CONTRAST_CONFIG_PATH=[the full path location of your YAML file] node --import @contrast/agent index.js",
  6. Since IBM Cloud runs the start script by default, you must change the start command to point to the ibmcloud-with-contrast line given in the previous step. Run the agent using:

    "start":"npm run ibmcloud-with-contrast"

    Now the scripts section of the package.json should look like the following:

    "scripts": {
    "bluemix-with-contrast": "CONTRAST_CONFIG_PATH=[the full path location of your YAML file] node --import @contrast/agent index.js",
    "start":"npm run bluemix-with-contrast”
  7. Push the application to IBM Cloud using:

    cf push <application-name> -t 180
  8. Run the agent with:

    npm start
  9. Exercise your application by performing either manual or automated testing to ensure your application is functioning correctly with the agent installed.

  10. Verify that your server is registered in Contrast and reports an instance of your application.