Starting the agentedit

The Elastic APM agent for Node.js needs to be started as the first thing in your application - before any other module is required/imported. This means that you should probably require and start it in your applications main file (usually index.js, server.js, or app.js).

There are two ways to start the Elastic APM agent for Node.js:

  • Require the elastic-apm-node module and call the start function on the returned agent:

    var apm = require('elastic-apm-node').start({
      // add configuration options here
    })
  • Require the elastic-apm-node/start script:

    var apm = require('elastic-apm-node/start')

    If using this approach, you can’t configure the agent by passing in an options object, but instead have to rely on one of the other methods of configuration.

If you are using Babel, you need to use the elastic-apm-node/start approach. Read more.