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 application environment to be set to active: true

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

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

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.js
const { Appsignal } = require("@appsignal/nodejs");
 
const appsignal = 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
});
 
module.exports = { appsignal }

Disable AppSignal for tests

Make sure to put active: false in your test configuration unless you want to submit all your test results. You can do this in the same way:

// appsignal.js
const { Appsignal } = require("@appsignal/nodejs");
 
const appsignal = new Appsignal({
  active: process.env.NODE_ENV === "production", // ignored in all envs except production
  name: "<YOUR APPLICATION NAME>",
  pushApiKey: "<YOUR API KEY>", // Note: renamed from `apiKey` in version 2.2.5
});
 
module.exports = { appsignal }

Want to help us improve this documentation page?

Create a pull request

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