Installation

You install the Node Agent by adding a dependency on the trackjs-node package and including it in your application. The agent is lightweight and dependency free.

npm install trackjs-node --save-exact
Adding a Dependency on TrackJS

Once installed, the agent listens for errors and other events to be reported back to your TrackJS Dashboard. The agent should be installed as early in your initialization process as possible so that the environment can be fully instrumented.

import { TrackJS } from "trackjs-node";

TrackJS.install({
  token: "YOUR_TOKEN"
});
Installing TrackJS in Node

Install Options

In addition to token, there are lots of options you can pass when installing the agent to better integrate with your application. Options can be used to:

  • add custom context to your errors
  • disable agent behaviors
  • customize reporting behavior

If you need the agent to do something specialized, checkout the onError option that allows you to manipulate errors before they are reported.

Isomorphism

If you don’t know whether your script will run on the client or server, you’ll need to put an adapter around the agent to provide this isomorphism. Here is an example:

export const TrackJS = (typeof window !== "undefined") ?
  require("trackjs").TrackJS :
  require("trackjs-node").TrackJS;
trackjs-loader.js
import { TrackJS } from './trackjs-loader.js';

TrackJS.install({
  token: "YOUR_TOKEN"
});'
main.js

TypeScript

The TrackJS-Node agent is written in Typescript and publishes types in the package. It will allow you to discover the options available on the agent.