---
title: "With a Bundler"
description: "Learn how to run your app with Sentry using a bundler plugin, without the --import flag."
url: https://docs.sentry.io/platforms/javascript/guides/express/install/bundler/
---

# With a Bundler | Sentry for Express

Are you unsure if you should use this installation method? Review our [installation methods](https://docs.sentry.io/platforms/javascript/guides/express/install.md).

If you build your server with a bundler, you can instrument your dependencies at build time with the Sentry bundler plugin instead of loading Sentry with the [`--import`](https://nodejs.org/api/cli.html#--importmodule) flag. Because the instrumentation is baked into your bundle, a plain top-level import of your instrument file is enough, and you can start your app with a regular `node` command, without the `--import` flag.

Use this method if you can't pass a command line flag to the Node.js binary, for example when your start command is fixed by your platform or process manager.

## [1. Create Your Instrument File](https://docs.sentry.io/platforms/javascript/guides/express/install/bundler.md#1-create-your-instrument-file)

Create a file named `instrument.(js|mjs)` in the root directory of your project that initializes Sentry:

```javascript
const Sentry = require("@sentry/node");
// ___PRODUCT_OPTION_START___ profiling
const { nodeProfilingIntegration } = require("@sentry/profiling-node");
// ___PRODUCT_OPTION_END___ profiling

Sentry.init({
  dsn: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
  // ___PRODUCT_OPTION_START___ profiling

  integrations: [
    // Add our Profiling integration
    nodeProfilingIntegration(),
  ],
  // ___PRODUCT_OPTION_END___ profiling
  // ___PRODUCT_OPTION_START___ performance

  // Set tracesSampleRate to 1.0 to capture 100%
  // of transactions for tracing.
  // We recommend adjusting this value in production
  // Learn more at
  // https://docs.sentry.io/platforms/javascript/guides/node/configuration/options/#tracesSampleRate
  tracesSampleRate: 1.0,
  // ___PRODUCT_OPTION_END___ performance
  // ___PRODUCT_OPTION_START___ profiling

  // Enable profiling for a percentage of sessions
  // Learn more at
  // https://docs.sentry.io/platforms/javascript/configuration/options/#profileSessionSampleRate
  profileSessionSampleRate: 1.0,
  // ___PRODUCT_OPTION_END___ profiling
});
```

*Other available variations of the above snippet: ESM*

## [2. Add the Sentry Bundler Plugin](https://docs.sentry.io/platforms/javascript/guides/express/install/bundler.md#2-add-the-sentry-bundler-plugin)

Add the Sentry plugin for your bundler to your build configuration. The plugin instruments your dependencies at build time, so the SDK no longer depends on `Sentry.init()` running before your other imports.

```javascript
import { sentryVitePlugin } from "@sentry/node/vite";

export default {
  plugins: [sentryVitePlugin()],
};
```

*Other available variations of the above snippet: Rollup, webpack, esbuild*

## [3. Import Your Instrument File First](https://docs.sentry.io/platforms/javascript/guides/express/install/bundler.md#3-import-your-instrument-file-first)

Import `instrument.(js|mjs)` at the very top of your application's entry point, before any other imports:

```javascript
// Import this first!
import "./instrument.mjs";

// Now import other modules
import express from "express";

// Your application code goes here
```

## [4. Run Your App](https://docs.sentry.io/platforms/javascript/guides/express/install/bundler.md#4-run-your-app)

Start your application as usual. No `--import` flag is required, because the instrumentation is already part of your bundle:

```bash
node app.mjs
```

If you can't use a bundler, review our other [installation methods](https://docs.sentry.io/platforms/javascript/guides/express/install.md) for alternatives that don't rely on the `--import` flag.
