How to instrument Strapi CMS with the Node Agent

  • Updated


How to instrument Strapi CMS with the Node Agent.


The following process describes how to instrument Strapi ( CMS with the Node Agent.  MongoDB and MySQL databases have been tested.

1. Database

1.1. MongoDB

  • You can follow more in-depth directions for MacOS, Windows, and Linux here - Install MongoDB Community Edition

  • For MacOS, if you have Brew set up, MongoDB can be installed quickly with:

    brew tap mongodb/brew
    brew install mongodb-community@4.4
    mongod --config /usr/local/etc/mongod.conf --fork

1.2. MySQL

  • The official “Configuring Strapi and MySQL” page documents setting up MySQL on Windows: Configuring MySQL on your Strapi project

  • For MacOS, if you have Brew set up, MySQL can be installed and run quickly with:

    brew update
    brew install mysql
    mysql.server start
  • Run MySQL in a new terminal tab or window:

    mysql -uroot
    CREATE DATABASE strapidb;
    SELECT user, plugin FROM mysql.user WHERE user IN ('root')\G;
    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'admin';

2. Strapi

  • From a directory of your choice, create a new Strapi project by running:

    npx create-strapi-app project-name
  • It will prompt you to choose an installation type. Choose Custom (manual settings)

  • There will be a text-based menu to Choose your main database.

  • MongoDB - Select Mongo. You can leave everything else set to the default.

  • MySQL - Select mysql. Set Database name to strapidb (or whichever name you chose when you created the database). Set username and password to “root” and “admin”, respectively. You can leave everything else set to the default.
  • You can follow the directions from this step onwards to create a simple Strapi application: Strapi - Quick Start Guide

3. Node Agent

  • In the directory for your Strapi project (e.g., project-name above), run:

    npm run build


    npm install @contrast/agent

    to get the latest Node Agent.

  • In the same directory, create a file called server.js (although any name will work) and paste these lines in to create an index file the agent can boot from:

    const strapi = require('@strapi/strapi');
  • Test to make sure you can start the app from this file without the agent by running node server.js. You should see the normal project information and welcome statements:Strapi_Welcome.png

  • If you don’t have any problems, you should be able to instrument the app with the Node Agent by running (assuming you either have CONTRAST environment variables or a contrast_security.yaml file located in one of the default locations - Configuration - Order of precedence to supply the necessary configuration to the agent):

    node -r @contrast/agent server.js

    and see the same welcome statements as above.  Agent configuration can optionally be supplied following the steps at Command line arguments for the Node.js Agent.

  • You can optionally add the above under the scripts section in your package.json file following the example at Install Node.js agent manually :
    "scripts": {
    	"contrast": "node -r @contrast/agent server.js",
  • Then start the application using npm run contrast
  • The application should now be visible in the Contrast UI:

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request