← Back to blog

Using Bun as JavaScript runtime

So, this morning I came across a tweet showcasing Bun. Bun is a ‘new’ runtime for JavaScript built from scratch. It claims to be a lot faster and compatible with NodeJS packages (NPM) and the NodeJS API functions. Let’s try that out!

”Bun’s goal is to run most of the worlds JavaScript outside of browsers, bringing performance and complexity enhancements to your future infrastructure, as well as developer productivity through better, simpler tooling.”

Installing Bun

Installing Bun is a really easy step:

curl https://bun.sh/install | bash

Just like NodeJS, Bun will install dependencies in a folder node_modules.bun and create a lockfile called bun.lockb, although it will be using the same package.json like NodeJS.


The Bun CLI comes with some really easy-to-use commands.

Some of them are:

# Run files
bun run

# Install packages (NPM compatible)
bun install

# Create new apps
bun create

# Upgrade Bun
bun upgrade

# Start Bun devserver
bun dev

# Add dependencies
bun add

# Remove dependencies
bun remove

Some of these commands also have shorthands like bun i or bun rm

More info can be found in the reference docs

Using the Bun runtime

When using bun run, you can run TypeScript & JavaScript files. The example on their website:

// http.js
export default {
  port: 3000,
  fetch(request) {
    return new Response("Welcome to Bun!");

When running bun run http.js, the server will start on localhost:3000 and respond with “Welcome to Bun!“.

Creating a new app from template

Bun comes out of the box with some templates, these include React, NextJS and a Discord interaction template. It’s also possible to use a Github repository as source:

# Create a Bun React app
bun create react ./react-app

# Create a Bun app from a repository
bun create eliancodes/eliancodes-frontend frontend

Keep in mind that Bun is still in Beta!

note: At this time, I won’t go any deeper in deploying using Bun, maybe something for the future 🤷‍♂️.

Written by Elian Van Cutsem

← Back to blog
  • Elians Astro Startkit

    Elians Astro Startkit

    I just published the setup I use for my personal projects. You can read more about it in this blogpost.

  • So, I'm leaving vBridge

    So, I'm leaving vBridge

    After spending a couple of years at vBridge Cloud, I'm leaving the company. I've worked at vBridge eversince I graduated. Now, It's time for a new adventure! I'm joining the DX-team at Astro full-time!

  • Becoming an Astro maintainer

    Becoming an Astro maintainer

    Since a week, I'm an Astro maintainer, in this post, I describe the process and my start in open source. I also give some insight in what I'm planning to work on.

  • 🍱 Brutal: A theme for Astro

    🍱 Brutal: A theme for Astro

    Brutal is a minimal neobrutalist theme for Astro. It's based on Neobrutalist Web Design, a movement that aims to create websites with a minimalistic and functional design. It has some integrations like Image Optimization, RSS, Sitemap, ready to get your SEO done right.

  • 🎤 Am I an international public speaker now?

    🎤 Am I an international public speaker now?

    A few weeks ago, I gave my first international keynote talk at JSWorld in Amsterdam. In this blogpost, I wanted to share some insights about the conference and my talk.

  • ✨ Building Blog tag index pages in Astro

    ✨ Building Blog tag index pages in Astro

    I wanted to add blog tag collection pages to my website. This way, people could filter on tags I used in my blog posts. Here is a guide on how I implemented it.