Help Docs

Install Node.js Agent

To install APM Insight Node.js agent, follow the below given instructions.

Video

Here's a quick video on how to install the Site24x7 APM Insight Node.js agent.

Installation steps for Node.js agent version 4.x and above

  1. Open your Node.js application.
  2. Access the node package manager (NPM).
  3. Use the command npm i apminsight --save to install an APM Insight Node.js agent from NPM. This will create a directory named apminsight under node_modules.
  4. You can either create a file and add the configuration values to it, or you can set the configuration values as environment variables.
    • Create a file and add configuration values

      Create a new file named apminsightnode.json and place it in the directory where you run the application. Add the below code snippet to the file.
      {
          "licenseKey": "license-key",
          "appName": "application-name",
          "port": "application-port"
      }

      If you are using proxy, add the below code snippet:

      {
          "licenseKey": "license-key",
          "appName": "application-name",
          "port": "application-port",
          "proxyServerHost": "proxy-server",
          "proxyServerPort": "proxy-port",
          "proxyAuthUser": "proxy-user-name",
          "proxyAuthPassword": "proxy-password"
      }

    • Set configuration values as environmental variables

      You can set configuration values as environment variables using the following keys:
      • licenseKey - APMINSIGHT_LICENSE_KEY
      • appName - APMINSIGHT_APP_NAME
      • port - APMINSIGHT_APP_PORT
      • proxyServerHost - APMINSIGHT_PROXYSERVER_HOST
      • proxyServerPort - APMINSIGHT_PROXYSERVER_PORT
      • proxyAuthUser - APMINSIGHT_PROXYAUTH_USER
      • proxyAuthPassword - APMINSIGHT_PROXYAUTH_PASSWORD

  5. Include the given code in the first line of your Node.js application start file, before any other require statements.
    JavaScript  Code snippet 
    Common JS require('apminsight');
    ECMAScript import apminsight from 'apminsight';
    TypeScript

    import AgentAPI from apminsight';
    AgentAPI.config();

    Alternative methods
    You can alternatively follow any of the methods below, which are common across all JavaScript types.

      • Using environmental variable:
        export NODE_OPTIONS="-r apminsight"
      • Include the require statement in the start script or when you start your application.
        node -r apminsight my-start-file.js
    Note

    -r is used to pre-load the specified module (apminsight module here) at startup.
    Only CommonJS modules support -r. Use --import to pre-load a TypeScript or ECMAScript module.

  6. Optional: You can install S247DataExporter on both Windows and Linux. You can set it up in either of these ways:

    • Enable the S247DataExporter using:
      • apminsightnode.json file: dataExporterEnabled - 'true'
      • environment(env) variables: APMINSIGHT_DATA_EXPORTER_ENABLED - 'true'
    • Setting custom S247DataExporter configurations for the host, status, and data port in: 
      • apminsightnode.json file: 
        dataExporterHost - String
        dataExporterDataPort - Int
        dataExporterStatusPort - Int
      • environment(env) variables:
        APMINSIGHT_DATA_EXPORTER_HOST - String
        APM_EXPORTER_DATA_PORT - Int
        APM_EXPORTER_STATUS_PORT - Int

    Below are the default configurations:

    Variable Default value
    Host localhost
    DataPort 20022
    StatusPort 20021

    For example:

    //apminsightnode.json
    {  
    ...
    "dataExporterHost": "localhost",
    "dataExporterStatusPort": "20021",
    "dataExporterDataPort": "2022"
    ...
    }
  7. Finally, restart the application and make some transactions to see data in the web client.

APM Insight Node.js versions 2.x and 3.x

We highly recommend you download the latest version of the APM Insight Node.js agent. However, if you need to download agent versions v2.x or v3.x for some reason, kindly refer to this KB article

Was this document helpful?

Would you like to help us improve our documents? Tell us what you think we could do better.


We're sorry to hear that you're not satisfied with the document. We'd love to learn what we could do to improve the experience.


Thanks for taking the time to share your feedback. We'll use your feedback to improve our online help resources.

Shortlink has been copied!