Swizec Teller - a geek with a hatswizec.com

Senior Mindset Book

Get promoted, earn a bigger salary, work for top companies

Senior Engineer Mindset cover
Learn more

    Bun – first impressions

    Heard of Bun? It's a new JavaScript runtime that recently reached 1.0.0. I've been using it on a few side-projects. Even at work!

    Ok so what is a runtime? A runtime is the environment that your code runs in. For JavaScript that's your browser, an Electron app, or NodeJS. Compiled languages like C or C# don't need a runtime because the compiled binary runs natively on your machine.

    Bun is a new runtime written from scratch. Optimized for performance, compatibility, and ease of use.

    Things I've liked about Bun

    A few things that stood out after using Bun for a few hours. I'm not an expert but so far Bun has been stupid easy to use.

    Bun is very very fast

    Using Bun feels faster. You have to try to appreciate the difference. It's like your computer feels lighter.

    When you run a NodeJS script, it's fast. Hit enter and your script gets to work. No lag you'd complain about.

    Then you run the same script with Bun and it's like omg what just happened? I barely finished hitting enter and it's done!? 🤯

    No mjs bullshit

    I don't know about you, but seeing Error [ERR_REQUIRE_ESM]: require() of ES Module makes me want to throw keyboards. You add a new library and the whole project blows up. (╯°□°)╯︵ ┻━┻

    This is because a few years ago NodeJS decided to support modern imports. import thing from 'file' instead of const thing = require('file). Fantastic!

    But they couldn't make both systems compatible. You have to choose between CommonJS (require) and Modules (import).

    Some libraries have migrated. Many haven't. You'll find out which is which when your project blows up after you add a dependency 🙃

    Bun doesn't have this problem. I don't know through what magic, but I like it. Everything just works.

    Native TypeScript support

    Write a file.ts run with bun run file.ts.

    Write a file.js run with bun run file.js.

    Direct native runtime support for TypeScript. No compiling, little configuration. Cross-import JavaScript into TypeScript and TypeScript into JavaScript. Bun don't care 😍

    No run-time support for types though. Jarred, creator of Bun, says that's not a goal either.

    Tools included

    Bun aims to become a full toolkit for JavaScript.

    Can't wait! The ease of going bun add library and bun run code.ts already feels amazing. Haven't looked for others yet.

    Compatible with the NodeJS ecosystem

    This has been my favorite part. Bun aims to work as a drop-in replacement for NodeJS, which means full ecosystem compatibility.

    APIs you're used to from NodeJS all work. I haven't bumped into anything broken, at least not in side-projects. Every library I've tried has also worked.

    Means you don't have to learn anything new \o/

    A couple sharp edges

    We all know how drop-in replacements work.

    If you use private packages, you'll have to move registry configuration from .npmrc to bunfig.toml. That's easy.

    In larger projects, you're likely to find things that are broken. When I tried running work stuff in Bun, there was a cryptic error with no good way to debug. Later we figured out our Logger library, used everywhere, doesn't like Bun – an outdated dependency maybe.

    Bun is new. Fantastic documentation, but if you run into a problem the documentation doesn't cover, you're likely one of the first people online to have this problem.

    All in all, Bun is my new favorite way to write CLI scripts.


    Published on October 20th, 2023 in JavaScript, TypeScript, NodeJS, Bun

    Did you enjoy this article?

    Continue reading about Bun – first impressions

    Semantically similar articles hand-picked by GPT-4

    Senior Mindset Book

    Get promoted, earn a bigger salary, work for top companies

    Learn more

    Have a burning question that you think I can answer? Hit me up on twitter and I'll do my best.

    Who am I and who do I help? I'm Swizec Teller and I turn coders into engineers with "Raw and honest from the heart!" writing. No bullshit. Real insights into the career and skills of a modern software engineer.

    Want to become a true senior engineer? Take ownership, have autonomy, and be a force multiplier on your team. The Senior Engineer Mindset ebook can help 👉 swizec.com/senior-mindset. These are the shifts in mindset that unlocked my career.

    Curious about Serverless and the modern backend? Check out Serverless Handbook, for frontend engineers 👉 ServerlessHandbook.dev

    Want to Stop copy pasting D3 examples and create data visualizations of your own? Learn how to build scalable dataviz React components your whole team can understand with React for Data Visualization

    Want to get my best emails on JavaScript, React, Serverless, Fullstack Web, or Indie Hacking? Check out swizec.com/collections

    Did someone amazing share this letter with you? Wonderful! You can sign up for my weekly letters for software engineers on their path to greatness, here: swizec.com/blog

    Want to brush up on your modern JavaScript syntax? Check out my interactive cheatsheet: es6cheatsheet.com

    By the way, just in case no one has told you it yet today: I love and appreciate you for who you are ❤️

    Created by Swizec with ❤️