15 Oct, 2024 - About 1 minute
Bun
Intro
Bun is an all-in-one toolkit for JavaScript and TypeScript apps. It ships as a single executable called bun.
At its core is the Bun runtime, a fast JavaScript runtime designed as a drop-in replacement for Node.js. It’s written in Zig and powered by JavaScriptCore under the hood, dramatically reducing startup times and memory usage
Install
curl -fsSL https://bun.sh/install | bash |
Using
The bun command-line tool also implements a test runner, script runner, and Node.js-compatible package manager, all significantly faster than existing tools and usable in existing Node.js projects with little to no changes necessary.
bun run start # run the `start` script |
bun CLI usage
The bun CLI contains a Node.js-compatible package manager designed to be a dramatically faster replacement for npm
, yarn
, and pnpm
. It’s a standalone tool that will work in pre-existing Node.js projects.
Run a JavaScript file or a package.json
script:
bun run path/to/file|script_name |
Run unit tests:
bun test |
Download and install all the packages listed as dependencies in package.json
:
bun install |
Add a dependency to package.json
:
bun add module_name |
Remove a dependency from package.json
:
bun remove module_name |
Create a new Bun project in the current directory:
bun init |
Start a REPL (interactive shell):
bun repl |
Upgrade Bun to the latest version:
bun upgrade |