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

# Detect when code is executed with Bun

Check `process.versions.bun` to detect whether code is running in Bun. This works in both JavaScript and TypeScript without extra type definitions.

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
if (process.versions.bun) {
  // this code will only run when the file is run with Bun
}
```

***

Alternatively, check for the `Bun` global, the same way you'd check for `window` to detect a browser.

> [!NOTE]
>
> In TypeScript, this check is a type error unless `@types/bun` is installed. Install it with `bun add -d @types/bun`.
> If you're using TypeScript 6.0 or later, you also need `"types": ["bun"]` in your `compilerOptions`. See [TypeScript 6
> and 7](https://bun.com/docs/typescript-6.md) for details.

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
if (typeof Bun !== "undefined") {
  // this code will only run when the file is run with Bun
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.