Install Node.js Agent
To install APM Insight Node.js agent, follow the below given instructions.
- Installation steps for Node.js agent version 4.x and above
- Installation steps for Node.js agent versions 2.x and 3.x
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:
- Open your Node.js application.
- Access the node package manager (NPM).
- 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.
- 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
-
- 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
- -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.
- Using environmental variable:
- Optional: For additional Node.js runtime-level statistics, ensure the @apminsight/native-stats package is installed.
- 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 the below given steps.
Installation instructions - agent versions 2.x and 3.x
- Open your Node.js application.
- Access the node packet manager (NPM).
- Use the command npm i apminsight --save to install an APM Insight Node.js agent from NPM. This will create an APM Insight directory under node_modules.
- Create a new file named apminsightnode.json and place it in the directory where you run the application. Add the below code snippet in the file.
{"licenseKey" : "<license-key>",
"appName" : "<application-name>",
"port" : <application-port> }If you are using proxy:
{"licenseKey" : "<license-key>",
"appName" : "<application-name>",
"port" : <application-port>,
"proxyServerHost" : "<proxy-server>",
"proxyServerPort" : <proxy-port>,
"proxyAuthUser" : "<proxy-user-name>",
"proxyAuthPassword" : "<proxy-password>"} - Follow any of the below:
- If you are using Common JS, follow the below instruction:
Include the following code in the first line of your Node.js application start file before any other require statements.
require('apminsight')() - If you are using ES, follow the below instruction:
Include the following code in the first line of your Node.js application start file before any other require statements.
import apminsight from 'apminsight';
apminsight.config() - If you are using a typescript application, follow the below steps:
i. Create a file named apminsight.d.ts in the same directory as your application start file.
ii. Add the below line to the apminsight.d.ts file.
declare module "apminsight";iii. Add the below lines to the first line of your application start file.
import * as apminsight from 'apminsight';
apminsight.config()
- If you are using Common JS, follow the below instruction:
- Copy and paste the license key in the apminsightnode.json file.
- Restart your application and make few transactions to view data in APM Insight client.
To add application port in application start file:
require(‘apminsight’)
(
{port:<application port>}
)
Set configuration values as environment variables:
You can set configuration values as environment variables using the following keys:
- License key - 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
- hostLicense - APMINSIGHT_HOSTLICENSE