Help Docs

Install the Node.js agent in a Docker container

The following steps outline the process of building, configuring, and deploying your dockerized Node.js application equipped with APM Insight.

Instrument your container

By making minimal modifications to your current Dockerfile, you can enable application monitoring using our Node.js agent. You can configure the agent by launching your updated Docker image with the environment variables set.

  1. Install the apminsight package

    • Add apminsight to the package.json file:
      You can simply add the apminsight package to your application's package.json file.
      "dependencies": {
          "apminsight": "latest",

      Install a specific version or explore alternative options available in the package.json format. Refer to the release notes of the Node.js agent for details on previous agent versions.

    • Add an installation command in Dockerfile:
      Suppose you don't want to make any changes related to the Node.js agent in your application and only want to make changes to your Dockerfile. In that case, you can add the below line to your Dockerfile to install the agent.
      RUN npm install apminsight --silent
  2. You can follow any of the below steps to load the Node.js agent:
    • Include the require statement in the start script, or you can edit the ENTRYPOINT to include the apminsight module.
      node -r apminsight my-start-file.js
    • Include the below code in the first line of your Node.js application start file before any other require statements.

      For Next.js, use @apminsight/next instead of apminsight.

  3. Adding configuration values

    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 copy it to the directory where the application will get started in the container.
      Add the below code snippet to the file:
      {"licenseKey" : "<license-key>",
      "appName" : "<application-name>",
      "port" : <application-port>}
      If you are using a 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:
      docker run -e APMINSIGHT_LICENSE_KEY="<license-key>" -e APMINSIGHT_APP_NAME="<application-name>" -e APMINSIGHT_APP_PORT="<application-port>" YOUR_IMAGE_NAME:latest
      The port number is optional. If it is not provided, Site24x7 will auto-detect the application's running port number.
  4. Build your Docker image as usual and start the container.

Related articles

How to install various APM Insight agents in a Docker container
Java | .NET | PHP | Python

How to install various APM Insight agents in a Kubernetes environment
Java | .NET | PHP | Node.js | Python

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!