> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useflytrap.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use Flytrap with Esbuild

> Use Flytrap to catch & replay both front-end & back-end bugs with a Esbuild bundled program

## Installing

Install the `useflytrap` package to your project.

<CodeGroup>
  ```bash npm theme={null}
  npm install useflytrap
  ```

  ```bash yarn theme={null}
  yarn add useflytrap
  ```

  ```bash pnpm theme={null}
  pnpm install useflytrap
  ```
</CodeGroup>

## 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.

<CodeGroup>
  ```typescript esbuild.build.js theme={null}
  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()] : [])]
  })
  ```
</CodeGroup>

<Snippet file="create-config.mdx" />

## 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.

<img height="200" src="https://mintcdn.com/flytrap-98/_ZYKplWiYxS4sMge/images/dashboard/capture.png?fit=max&auto=format&n=_ZYKplWiYxS4sMge&q=85&s=ce61d7b322d5d0cb849a4c651416a277" className="rounded-lg" className="rounded-lg" data-path="images/dashboard/capture.png" />

## Example

<Card
  title="Esbuild usage example"
  icon={
	<svg width="24" height="24" viewBox="0 0 200 200"  xmlns="http://www.w3.org/2000/svg">
		<circle cx="100" cy="100" r="100" fill="#FFCF00"/>
		<path d="M47.5 52.5L95 100l-47.5 47.5m60-95L155 100l-47.5 47.5" fill="none" stroke="#191919" stroke-width="24"/>
	</svg>
}
  href="https://github.com/useflytrap/flytrap-js/tree/main/examples/with-express"
>
  See how you can use Flytrap with Esbuild in an example Express API
</Card>
