The Atatus Node.js agent helps you in troubleshooting your Node.js application problems and also identifies performance issues before it becomes apparent to your users. It also captures unhandled exceptions and HTTP failures in production to determine which part of your Node.js application is slower or producing lots of errors.

Create a free account to start monitoring your Node.js apps.

Installation & Setup

Step 1: Install Atatus Node.js Package

copy
icon/buttons/copy
npm install --save atatus-nodejs

Step 2: Create atatus.js Initialization File

Create an atatus.js file in your project root with the following code:

copy
icon/buttons/copy
// atatus.js - Atatus Agent Initialization
// Place this file in your project root

// For JavaScript (ES Modules):
import atatus from 'atatus-nodejs';

// For TypeScript:
// import * as atatus from 'atatus-nodejs';


// Option 1: Hardcoded configuration
atatus.start({
    licenseKey: "YOUR_LICENSE_KEY",
    appName: "YOUR_APP_NAME"
});

// Option 2: Read from environment variables
// atatus.start({
//     licenseKey: process.env.ATATUS_LICENSE_KEY,
//     appName: process.env.ATATUS_APP_NAME
// });

// Option 3: Load from .env file using dotenv (ES module way)
// import 'dotenv/config';
// atatus.start({
//     licenseKey: process.env.ATATUS_LICENSE_KEY,
//     appName: process.env.ATATUS_APP_NAME
// });

export default atatus;

Step 3: Start Your Application

Use the -r flag to preload the atatus.js file when starting your Node.js application:

copy
icon/buttons/copy
node -r ./atatus.js ./app/server.js

An example Docker command:

copy
icon/buttons/copy
CMD ["node", "-r", "./atatus.js", "server.js"]

Step 4: Restart Your Server

Just restart your server and access it. You will visualize your application's metrics within minutes.


Configuration Options

You can configure the Atatus agent in three ways:

Option Description
Hardcoded Set licenseKey and appName directly in the atatus.start() call
Environment Variables Use process.env.ATATUS_LICENSE_KEY and process.env.ATATUS_APP_NAME
dotenv Load configuration from a .env file using import 'dotenv/config'

Using Environment Variables

copy
icon/buttons/copy
export ATATUS_LICENSE_KEY="YOUR_LICENSE_KEY"
export ATATUS_APP_NAME="YOUR_APP_NAME"

# To enable analytics feature
export ATATUS_ANALYTICS=true
export ATATUS_LOG_BODY=all
export ATATUS_ANALYTICS_CAPTURE_OUTGOING=true

Using dotenv

Install the dotenv package and create a .env file:

copy
icon/buttons/copy
npm install dotenv
copy
icon/buttons/copy
# .env file
ATATUS_LICENSE_KEY=your_actual_license_key
ATATUS_APP_NAME=your_app_name

For more advanced options on installing your monitoring code, view customizing agent.

Error Handling For ES Modules(Babel) & TypeScript

If you are using Atatus Node.js agent, for instance along with Babel, TypeScript for Node.js, you need to create and import atatus-promise-error-handler.js file.

// Atatus Promise Error Handling
// atatus-promise-error-handler.js

import atatus from 'atatus-nodejs';

let unhandledRejectionHandler = function (err) {
    // console.debug('Atatus agent caught unhandled rejections: ', err.message)

    return new Promise((resolve, reject) => {
        atatus.notifyError(err)
        resolve()
    });
}

let load = function() {
    // Prepend the listener if we can (Node 6+)
    if (process.prependListener) {
      process.prependListener('unhandledRejection', unhandledRejectionHandler)
    } else {
      process.on('unhandledRejection', unhandledRejectionHandler)
    }
}

load();

exports.destroy = function() {
    process.removeListener('unhandledRejection', unhandledRejectionHandler)
}