AppSignal for Node.js configuration

In this section, we'll explain how to configure AppSignal, what can be configured in the Node.js package, and what the minimal configuration needed is.

Minimal required configuration

The minimal required configuration needed by AppSignal for Node.js is the following items. If they are not present, AppSignal will not send any data to AppSignal.com.

  • A valid Push API Key
  • An application name
  • An application environment (development/production/test by setting NODE_ENV)
  • The setting active: true

The integration supports loading its configuration via options passed to the Appsignal constructor. We recommend creating an appsignal.cjs file to require and initialize AppSignal.

// appsignal.cjs
const { Appsignal } = require("@appsignal/nodejs");
 
new Appsignal({
  active: true,
  name: "<YOUR APPLICATION NAME>",
  pushApiKey: "<YOUR API KEY>", // Note: renamed from `apiKey` in version 2.2.5
});

Alternatively, you can configure the agent using system environment variables. AppSignal will automatically become active if the APPSIGNAL_PUSH_API_KEY environment variable is set.

export APPSIGNAL_PUSH_API_KEY="<YOUR API KEY>"
export APPSIGNAL_APP_NAME="<YOUR APPLICATION NAME>"
export APPSIGNAL_APP_ENV="production"

Configuration options

Read about all the configuration options on the options page.

Application environments

An application can have multiple environments such as "development", "test", "staging" and "production".

To separate the errors and performance issues that occur in the "development" environment and those in "production", it's possible to set the environment in which the application is running with the NODE_ENV environment variable.

If you activate AppSignal per environment, you can set the active property of the options you pass into the constructor conditionally:

// appsignal.cjs
const { Appsignal } = require("@appsignal/nodejs");
 
new Appsignal({
  active: process.env.NODE_ENV !== "development",
  name: "<YOUR APPLICATION NAME>",
  pushApiKey: "<YOUR API KEY>", // Note: renamed from `apiKey` in version 2.2.5
});

This will also disable AppSignal when running your tests.

Need more help?

Contact us and speak directly with the engineers working on AppSignal. They will help you get set up, tweak your code and make sure you get the most out of using AppSignal.

Contact us

Start a trial - 30 days free

AppSignal is a great way to monitor your Ruby, Elixir & Node.js applications. Works great with Rails, Phoenix, Express and other frameworks, with support for background jobs too. Let's improve your apps together.

Start a trial