Basic Usage
Learn how to use the Traque Node.js SDK for error tracking and monitoring in your application.
Basic Usage
After installing and configuring the Traque Node.js SDK, you can start using it to monitor and track errors in your Node.js application.
Initialization
First, import and initialize the SDK in your application:
Automatic Error Capturing
The SDK can automatically capture unhandled exceptions and promise rejections in your application.
Enable Auto-Capture
Disable Auto-Capture
Manual Error Capturing
You can manually capture errors with additional context when needed:
Framework Integration
Express.js
For Express.js applications, add the error handler middleware:
Fastify
For Fastify applications, set up the error handler:
Hono
For Hono applications, configure the error handler:
HTTP Context
When using framework integration, the SDK automatically captures the following HTTP context:
- Request URL
- HTTP method
- Status code
- Status message
- Client IP address
Best Practices
Single Instance
Create a single Traque instance and reuse it throughout your application:
Environment-Based Configuration
Configure the SDK differently based on your environment:
Error Context
Add relevant context when manually capturing errors:
Common Issues
Network Errors
The SDK handles network errors gracefully. If the service is temporarily unavailable, the SDK will:
- Log the error locally
- Queue the error report for retry
- Continue normal application operation
Configuration Validation
The SDK validates your configuration during initialization. Common issues include:
- Missing or invalid API key
- Invalid service URL
- Invalid environment value
Make sure to check your environment variables and configuration values if you encounter initialization errors.