Install the useflytrap package to your project.

npm install useflytrap

Add Flytrap code transform

Add the Flytrap code transform to your Esbuild configuration, so that all your code gets properly processed for replaying. This is an example configuration of using Esbuild with an Express API.

import { build } from 'esbuild'
import { FlytrapTransformPlugin } from 'useflytrap/transform'

await build({
	entryPoints: ['./src/index.ts'],
	outdir: 'dist',
	outExtension: {
		'.js': '.cjs'
	format: 'cjs',
	bundle: true,
	platform: 'node',
	target: 'node18',
	packages: 'external',
	// only add in production
	plugins: [...(process.env.NODE_ENV === 'production' ? [FlytrapTransformPlugin.esbuild()] : [])]

Create your Flytrap configuration

Next up, create your Flytrap configuration file. The configuration file defines what project you are capturing & replaying for, and the replay & capture behavior.

You can get the values for your Flytrap configuration file by creating a project as seen below.

Create project with credentials
import { defineFlytrapConfig } from 'useflytrap'

export default defineFlytrapConfig({
	projectId: 'your-project-id',
	captureId: 'capture id for replaying',
	publicApiKey: 'your public api key',
	secretApiKey: 'your secret api key',
	privateKey: 'your private key',
	mode: 'capture'

Catch your first bug

Now your app will be enabled with Flytrap. You can test out the setup by throwing an error in your development environment.


Esbuild usage example

See how you can use Flytrap with Esbuild in an example Express API