Node.js error tracking installation
- 1
Install the package
RequiredInstall the PostHog Node.js library using your package manager:
- 2
Initialize PostHog
RequiredInitialize the PostHog client with your project token:
Node.js - 3
Send an event
RecommendedOnce installed, you can manually send events to test your integration:
Node.js - 4
Configure exception autocapture
RecommendedYou can enable exception autocapture when initializing the PostHog client to automatically capture uncaught exceptions and unhandled rejections in your Node app.
Node.jsIf you are using the Express framework, you will need to import and call
setupExpressErrorHandlerwith your PostHog client and Express app. This is because Express handles uncaught exceptions internally meaning exception autocapture will not work by default.server.tsNote: Error tracking requires access the file system to process stack traces. Some providers, like Cloudflare Workers, do not support Node.js runtime APIs by default and need to be included as per their documentation.
- 5
Manually capture exceptions
OptionalIf you need to manually capture exceptions, you can do so by calling the
captureExceptionmethod:Node.jsThis is helpful if you've built your own error handling logic or want to capture exceptions normally handled by the framework.
- 6

