New to Rust? Grab our free Rust for Beginners eBook Get it free →
100+ Bun Commands to Speed Up Your TypeScript Workflow (Bun CLI Cheat Sheet)

Bun has rapidly become one of the fastest and most reliable JavaScript runtimes. In today’s guide, we have compiled over 100 Bun commands with easy examples to help you become a Bun expert.
What is Bun and Why Use It?
Bun is an all-in-one toolkit for JavaScript and TypeScript applications. It is designed to be incredibly fast and provides a drop-in replacement for Node.js. We use Bun because it handles packaging, testing, and bundling in a single tool, which reduces the need for multiple external dependencies. Its speed comes from the Zig programming language and the JavaScriptCore engine.
How to Install Bun
Before we dive into the specific Bun CLI commands, we need to install Bun on our system. The installation process is straightforward and works on macOS, Linux, and Windows via WSL.
Example: curl -fsSL https://bun.sh/install | bash
After running this command, restart your terminal to start using Bun.
Verify Installation
Once installed, we should verify that Bun is ready to use. This command checks the currently installed version.
Example: bun –version
Basic Setup and Initialization Bun Commands
These Bun CLI commands help us start new projects and configure our environment. We will learn how to create applications from scratch using the terminal.
bun init
This command initializes a new project in the current directory. It creates a default package.json file and sets up a basic project structure.
Example: bun init
bun init -y
We use this command to initialize a project without answering any configuration questions. It accepts all default settings immediately.
Example: bun init -y
bun create
This command creates a new project from a template. It is the standard way to start a new application using frameworks like React or Next.js.
Example: bun create react my-app
bun create next
We use this specific command to generate a new Next.js application using Bun as the runtime.
Example: bun create next my-next-app
bun create express
This command generates a basic Express server template. It sets up the necessary files for a backend API quickly.
Example: bun create express my-server
bun upgrade
This command updates the Bun runtime to the latest version. It ensures we have the newest features and security patches.
Example: bun upgrade
bun upgrade –canary
We use this command to upgrade to the latest unstable version. It is useful for testing upcoming features before they are officially released.
Example: bun upgrade –canary
bun help
This command displays the help menu. It lists all available Bun commands and provides a brief description of each one.
Example: bun help
bun -h
This is a shorter version of the help command. It provides the same information but is faster to type.
Example: bun -h
Running Code and Scripts
This section covers Bun commands used to execute JavaScript and TypeScript files. These commands are the most frequently used in daily development.
bun run
We use this command to execute a JavaScript or TypeScript file directly. It runs the code using the Bun runtime environment.
Example: bun run index.ts
bun
Typing just bun followed by a filename is a shortcut for bun run. It produces the same result with less typing.
Example: bun index.ts
bun run –watch
This command runs a file and automatically restarts when changes are detected. It is perfect for development environments.
Example: bun run –watch index.ts
bun run –hot
We use this command to enable hot reloading. It reloads the code without restarting the entire process, preserving some state.
Example: bun run –hot index.ts
bun –bun
This flag forces a script to run with Bun instead of Node.js. It is useful when npm scripts default to Node.
Example: bun –bun run script.js
bun run dev
This command runs the “dev” script defined in the package.json file. It is commonly used to start development servers.
Example: bun run dev
bun run start
We execute this command to run the “start” script in package.json. It typically launches the production server.
Example: bun run start
bun run build
This command executes the “build” script found in package.json. It usually bundles the application for production.
Example: bun run build
bun –silent
We use this flag to suppress the output of the bun command. It is helpful when we only want to see errors.
Example: bun –silent run script.ts
bun –cwd
This command sets the current working directory. It allows us to run a script in a different folder from where we are currently located.
Example: bun –cwd ./apps/main run start
bun –env-file
This command loads environment variables from a specific file. It is useful for managing different configurations.
Example: bun –env-file=.env.production run start
Package Management Bun Commands
These Bun CLI commands manage dependencies in our project. They replace tools like npm or yarn with much faster alternatives.
bun install
This command installs all dependencies listed in the package.json file. It creates the node_modules folder if it does not exist.
Example: bun install
bun add
We use this command to add a new package to the project. It updates the package.json and bun.lockb files automatically.
Example: bun add lodash
bun add -d
This flag adds a package as a development dependency. These packages are only needed during the development phase.
Example: bun add -d typescript
bun add -g
We use this flag to install a package globally on our system. This makes the package available in any terminal window.
Example: bun add -g prettier
bun remove
This command uninstalls a package from the project. It removes the package from package.json and the node_modules folder.
Example: bun remove lodash
bun remove -g
We use this to remove a globally installed package. It cleans up our global environment.
Example: bun remove -g prettier
bun update
This command updates all dependencies to their latest versions. It respects the version ranges specified in package.json.
Example: bun update
bun update package-name
We use this to update a specific package to the latest version. It targets only the named dependency.
Example: bun update react
bun link
This command creates a symlink to the current package in the global folder. It is useful for testing local packages.
Example: bun link
bun link package-name
We use this command to link a globally installed package to the current project. It allows us to use local versions of libraries.
Example: bun link my-local-library
bun unlink
This command removes the symlink created by bun link. It disconnects the local package from the global registry.
Example: bun unlink
bun install –production
We use this flag to install only production dependencies. It skips development tools to keep the final image small.
Example: bun install –production
bun install –frozen-lockfile
This command installs dependencies without updating the lockfile. It is essential for continuous integration pipelines.
Example: bun install –frozen-lockfile
bun install –force
We use this command to force a fresh install. It ignores the cache and re-downloads all packages.
Example: bun install –force
bun install –no-save
This command installs a package without adding it to package.json. It is useful for temporary testing.
Example: bun install –no-save temporary-package
bun install –offline
We use this command to install packages using only the local cache. It fails if a package is not cached.
Example: bun install –offline
Advanced Package Manager Utilities
These Bun commands provide deeper control over packages and caching. We use them for debugging and managing system resources.
bun pm
This command acts as the entry point for package manager utilities. It provides subcommands for specific package operations.
Example: bun pm
bun pm bin
This command prints the path to the binary folder where executable packages are stored. It helps locate command line tools.
Example: bun pm bin
bun pm bin -g
We use this to print the path to the global binary folder. It shows where global tools are installed.
Example: bun pm bin -g
bun pm ls
This command lists all installed dependencies in a tree format. It shows the relationship between packages.
Example: bun pm ls
bun pm cache
This command manages the Bun package cache. It helps free up disk space or troubleshoot installation issues.
Example: bun pm cache
bun pm cache rm
We use this command to clear the entire package cache. It forces Bun to download fresh packages on the next install.
Example: bun pm cache rm
bun pm cache ls
This command lists all the packages currently stored in the cache. It shows the name and size of cached items.
Example: bun pm cache ls
bun pm migrate
This command migrates the installation from npm or yarn to Bun. It attempts to convert the lockfile automatically.
Example: bun pm migrate
bun pm hash
We use this command to generate a hash of the current lockfile. It is useful for cache busting in CI pipelines.
Example: bun pm hash
bun pm whoami
This command displays the currently authenticated user for the registry. It verifies if we are logged in to publish packages.
Example: bun pm whoami
Testing and Debugging Commands
Testing is a core feature of Bun. These commands allow us to run tests and debug our code efficiently.
bun test
This command runs all test files in the project. It matches files ending with .test.js or .spec.ts by default.
Example: bun test
bun test file.test.ts
We use this command to run a specific test file. It focuses the testing on one part of the application.
Example: bun test utils.test.ts
bun test –watch
This command runs tests in watch mode. It automatically re-runs tests when files are saved.
Example: bun test –watch
bun test –coverage
We use this flag to generate a test coverage report. It shows which parts of the code are tested.
Example: bun test –coverage
bun test –bail
This command stops running tests after the first failure. It helps us fix errors one by one quickly.
Example: bun test –bail
bun test –timeout
We use this flag to set a time limit for tests. If a test takes too long, it will be marked as failed.
Example: bun test –timeout 5000
bun test –only
This command runs only the tests marked with .only. It is useful for debugging a specific feature.
Example: bun test –only
bun test –todo
We use this command to include tests marked as todo in the run. It helps track unfinished work.
Example: bun test –todo
bun test –grep
This command runs tests that match a specific pattern or string. It allows us to filter tests by name.
Example: bun test –grep “user login”
bun test –update-snapshots
We use this flag to update snapshot files. It changes the stored snapshots to match the current output.
Example: bun test –update-snapshots
bun test –rerun-each
This command runs each test multiple times. It helps find flaky tests that do not fail consistently.
Example: bun test –rerun-each 10
bun test –sequence
We use this flag to run tests in a specific order. It is helpful for debugging dependency issues.
Example: bun test –sequence
Build and Bundling Commands
Bun has a built-in bundler that is incredibly fast. These commands help us bundle our code for production.
bun build
This command bundles the project entry points. It creates optimized files for the browser or server.
Example: bun build ./index.ts
bun build –outdir
We use this flag to specify the output directory for bundled files. It organizes our build artifacts.
Example: bun build ./index.ts –outdir ./dist
bun build –minify
This command minifies the output code. It removes whitespace and shortens variable names to reduce file size.
Example: bun build ./index.ts –minify
bun build –splitting
We use this flag to enable code splitting. It creates multiple smaller files instead of one large file.
Example: bun build ./index.ts –splitting
bun build –format
This command specifies the output module format. We can choose between esm, cjs, and iife.
Example: bun build ./index.ts –format esm
bun build –target
We use this flag to set the target environment. It tells Bun to optimize for the browser or Node.js.
Example: bun build ./index.ts –target browser
bun build –compile
This command compiles the script into a standalone executable. It allows us to run the code without Bun installed.
Example: bun build ./index.ts –compile –outfile my-app
bun build –no-minify
We use this flag to disable minification. It keeps the output code readable for debugging purposes.
Example: bun build ./index.ts –no-minify
bun build –sourcemap
This command generates a source map for the output. It helps debug the original code in the browser.
Example: bun build ./index.ts –sourcemap
bun build –define
We use this flag to replace global identifiers with constants. It is useful for setting environment variables.
Example: bun build ./index.ts –define process.env.NODE_ENV='”production””
bun build –external
This command marks a package as external. It excludes the package from the final bundle.
Example: bun build ./index.ts –external react
bun build –loader
We use this flag to specify how files are loaded. It tells Bun how to handle file extensions like .png or .svg.
Example: bun build ./index.ts –loader .png=file
bun build –public-path
This command sets the public path for assets. It prefixes the URLs of static files.
Example: bun build ./index.ts –public-path /assets/
bun build –banner
We use this flag to add a string to the top of the output file. It is often used for license headers.
Example: bun build ./index.ts –banner “/* License MIT */”
bun build –footer
This command adds a string to the bottom of the output file. It can be used for execution triggers.
Example: bun build ./index.ts –footer “console.log(‘Built with love’);”
Utility and Tooling Commands
These Bun CLI commands provide extra utility. They help with encryption, file manipulation, and shell operations.
bun x
This command executes a package binary without installing it permanently. It is similar to npx in the Node ecosystem.
Example: bun x cowsay “Hello World”
bun repl
We use this command to start an interactive Read-Eval-Print Loop. It allows us to write JavaScript code directly in the terminal.
Example: bun repl
bun run shell-command
Bun can run shell commands directly. This acts as a cross-platform shell interpreter.
Example: bun run “echo Hello && ls”
bun hash
This command generates a hash for a file or string. We use it for integrity checks.
Example: bun hash package.json
bun escape
We use this command to escape special characters in a string. It makes the string safe for command line usage.
Example: bun escape “hello ‘world'”
bun unescape
This command reverses the escaping process. It returns the string to its original form.
Example: bun unescape “hello%20world”
bun resolve
We use this command to resolve a module path. It finds the location of a package in the file system.
Example: bun resolve react
bun highlight
This command applies syntax highlighting to a source file. It outputs the file with ANSI color codes.
Example: bun highlight index.ts
bun completions
This command generates shell completions scripts. It enables tab completion for Bun commands in your terminal.
Example: bun completions
bun completions bash
We use this to generate completion scripts specifically for the Bash shell.
Example: bun completions bash
bun completions zsh
This command generates completion scripts for the Zsh shell. It improves the workflow for Zsh users.
Example: bun completions zsh
bun completions fish
We use this to generate completion scripts for the Fish shell.
Example: bun completions fish
Global Configuration and Flags
These Bun commands modify how the runtime behaves globally. They adjust memory limits, installation paths, and logging levels.
bun –verbose
We use this flag to enable detailed logging. It provides more information about what Bun is doing internally.
Example: bun –verbose run index.ts
bun –no-install
This command disables automatic installation of missing packages. It forces the script to fail if a dependency is missing.
Example: bun –no-install run index.ts
bun –config
We use this flag to specify a custom configuration file. It allows us to load settings from a specific path.
Example: bun –config bunfig.toml run index.ts
bun –tsconfig-override
This command forces Bun to use a specific tsconfig.json file. It overrides the default lookup logic.
Example: bun –tsconfig-override ./config/tsconfig.json run index.ts
bun –no-macros
We use this flag to disable macro execution. It prevents specific code transformations during the build process.
Example: bun –no-macros build index.ts
bun –smol
This command runs Bun in a memory-efficient mode. It is useful for environments with limited RAM.
Example: bun –smol run server.ts
bun –revision
This command prints the specific git revision used to build the Bun executable. It is useful for precise bug reporting.
Example: bun –revision
bun –cpu-rate
We use this flag to throttle the CPU usage. It slows down execution which can help isolate timing bugs.
Example: bun –cpu-rate 50 run index.ts
bun –preload
This command preloads a script before the main entry point. It is useful for setting up test environments.
Example: bun –preload setup.ts run test.ts
bun –main-fields
This flag changes how Bun resolves package.json fields. It allows customizing the entry point resolution logic.
Example: bun –main-fields “module,main” build index.ts
Environment and Node.js Compatibility
These commands help Bun interact with Node.js projects and manage environment variables efficiently.
bun –env
This command lists all environment variables available to the Bun process. It helps debug configuration issues.
Example: bun –env
bun –print-process-cpu
We use this flag to print CPU usage statistics. It helps profile the performance of scripts.
Example: bun –print-process-cpu run server.ts
bun –jsx-production
This command optimizes JSX for production. It removes development specific checks and comments.
Example: bun –jsx-production build index.tsx
bun –jsx-runtime
We use this flag to set the JSX runtime. It changes how JSX is transformed into JavaScript.
Example: bun –jsx-runtime react build index.tsx
bun –jsx-import-source
This command sets the import source for JSX. It is useful for libraries like Emotion or Theme UI.
Example: bun –jsx-import-source @emotion/react build index.tsx
bun –jsx-fragment
We use this flag to set the fragment component for JSX. It replaces the default fragment wrapper.
Example: bun –jsx-fragment Fragment build index.tsx
bun –jsx-factory
This command sets the function used to create JSX elements. It is needed for non-React libraries.
Example: bun –jsx-factory h build index.tsx
bun –loader
We use this flag to define loaders for specific file extensions. It tells Bun how to parse unknown file types.
Example: bun –loader .txt=text run index.ts
bun –no-summary
This command disables the summary table output at the end of a test run. It produces a cleaner output.
Example: bun –no-summary test
Conclusion
Mastering these Bun CLI commands will significantly speed up your development process and make your workflow more efficient. We have covered everything from basic installation to advanced bundling and testing commands in this guide. Keep this reference handy as you build your next project. For more detailed technical specifications, you can always check the official Bun Documentation.
Ready to level up your development skills? Compare TypeScript vs Node.js
to understand the core differences in performance, or prepare for your next career move with our curated list of the top 50 TypeScript interview questions.




