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
In App Startup Script
Install Atatus Node.js package.
copynpm install --save atatus-nodejs
Set environment variables
copyexport 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
Add
-r atatus-nodejs/start
to your app's startup script. For example, if your application's entry point is./app/server.js
, then you would use the require flag like so:copynode -r atatus-nodejs/start ./app/server.js
An example Docker command:
copyCMD ["node", "-r", "atatus-nodejs/start", "server.js"]
Restart your Node.js server.
Just restart your server and access it. You will visualize your application's metrics within minutes.
For CommonJS
Install Atatus Node.js package.
copynpm install --save atatus-nodejs
Require Atatus in your Node.js app and invoke start with your License key and App name:
copy// It must be placed above all other 'require' statements var atatus = require("atatus-nodejs"); atatus.start({ licenseKey: "YOUR_LICENSE_KEY", appName: "YOUR_APP_NAME" });
For more advanced options on installing your monitoring code, view customizing agent.
Restart your Node.js server.
Just restart your server and access it from your web app or mobile app or curl. You will visualize your application's metrics within minutes.
require("atatus-nodejs")
should be the first line of your server code(example: server.js or index.js) and placed above all other 'require' statements. Otherwise instrumentation will not work.
For ES Modules
If you are using ES Modules, for instance along with Babel for Node.js, all import statements are evaluated prior to calling any functions. Therefore, you need to import the atatus-nodejs/start module before all other 'import' statements.
Install Atatus Node.js package.
copynpm install --save atatus-nodejs
Import atatus-nodejs/start in your Node.js app.
copy// It must be placed above all other 'require' statements import atatus from 'atatus-nodejs/start'; // startMonitor is different from "start" function. It is used only when you are using Babel(Typescript) or ES6. atatus.startMonitor();
Create a file atatus-config.js file in the directory where you run your Node.js server.
copy// atatus-config.js module.exports = { licenseKey: "YOUR_LICENSE_KEY", appName: "YOUR_APP_NAME" }
If this file is not found, you will get the error "License key is missing!". To fix this error, you can set the path of atatus-config.js in the env variable as follows
copyexport ATATUS_CONFIG_FILE=/path/to/atatus-config.js
For more advanced options on installing your monitoring code, view customizing agent.
Restart your Node.js server.
Just restart your server and access it from your web app or mobile app or curl. You will visualize your application's metrics within minutes.
For TypeScript
If you are using TypeScript, all import statements are evaluated prior to calling any functions. Therefore, you need to import the atatus-nodejs/start module before all other 'import' statements.
Install Atatus Node.js package.
copynpm install --save atatus-nodejs
Import atatus-nodejs/start in your Node.js app.
copy// It must be placed above all other 'require' statements import * as atatus from 'atatus-nodejs/start'; // startMonitor is different from "start" function. It is used only when you are using Babel(Typescript) or ES6. atatus.startMonitor();
Create a file atatus-config.js file in the directory where you run your Node.js server.
copy// atatus-config.js module.exports = { licenseKey: "YOUR_LICENSE_KEY", appName: "YOUR_APP_NAME" }
If this file is not found, you will get the error "License key is missing!". To fix this error, you can set the path of atatus-config.js in the env variable as follows
copyexport ATATUS_CONFIG_FILE=/path/to/atatus-config.js
For more advanced options on installing your monitoring code, view customizing agent.
Restart your Node.js server.
Just restart your server and access it from your web app or mobile app or curl. You will visualize your application's metrics within minutes.
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)
}