Bun is disrupting JavaScript land

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
it is September 8th 2023 and you're watching the code report yesterday was a huge day for soy devs Mojo became generally available a super set of python that's up to 35 000 times faster but JavaScript also got way faster thanks to a new Swiss army knife called bun and that means it's time for some new stickers on my MacBook Pro JavaScript developers have grown tired of Reinventing new Frameworks so now we're building an entirely new JavaScript runtimes in the beginning we had node.js it then rearranged the letters to make Dino and now we've got bun fresh out of the oven which just hit 1.0 this morning and you should take notice because it can run your JavaScript code faster than any other tool known to man but not just that it also acts as a bundler like webpack or Veet a test Runner like jest or Karma and a package manager like npm or yarn in addition it's almost fully compatible with existing node.js apis but has its own set of Highly optimized apis that actually make it fun to build high performance server-side applications with JavaScript before we get into it though I want to show you another awesome new tool from our sponsor devgpt by now you've heard of tools like chat gbt and co-pilot but devgpt takes AI code generation to the next level by integrating directly with your git repo giving the AI the full context of your Tech stack and project after writing a prompt to fix a bug or create a feature It'll ask follow-up questions to write highly targeted and useful code once the code is generated you can then sync those changes to your local project instantly then you could prompt it to generate some unit tests to validate that code it's like having an automated engineer by your side who can take care of your GitHub issues and jira tickets instantly without complaining you can try it out for free yourself right now with the link below but now let's get back to bun first of all how do they make this thing so fast one major difference compared to node and Dino which uses the V8 engine from chrome bun uses JavaScript core from Safari which is known to be optimized for faster startup times in addition bun is implemented in the zig programming language they've put a focus on profile and performance bottlenecks and Implement apis in native code the end result is a hello world with typescript that's five times faster than es build keep in mind though benchmarks can always be cherry-picked and rarely reflect real world performance it's fun to go fast but because I only have 12 monthly active users on my website it doesn't make a huge difference for me what I care about is the developer experience can bun make my life easier well first up it's got awesome typescript support out of the box you can immediately start writing typescript code without any configuration or headaches and it also supports jsx and hot reloading which means you don't need any weird dependencies like node mod and concurrently to recompile your code when things change that's cool but one of the absolute worst things about node has been the transition from common JS to es modules what's cool about bun is that you can just use import and require in the same file and everything just magically works and it's compatible with existing node.js packages which means you don't have to reinvent the wheel for every little thing you want to implement Dino also added npm support as well recently but what I really like about bun is its native apis for example to read and write to the file system we can access the global bun runtime and make a reference to a file then lazily read it or parse its Json that may not seem like a big deal but in node.js there are three different ways to do this same thing read file with callbacks read file with promises or read file sync you can actually use all of those in bun but not only are the native apis faster they're easier to use in addition it's extremely easy to set up an HTTP server in bun by simply calling the serve method you then use familiar browser Primitives like Fetch and response to build your API that'll take you pretty far but there's also Frameworks that work with bun like Elysia that claims to be 18 times faster than express.js and node but it also works with hono which has been my go-to framework for building apis recently bun has tons of other simplifications as well like it makes websockets nice and simple out of the box without any extra dependencies and you can use environment variables without things like dot EnV pretty cool but as the name implies bun is also a bundler the bun build command will take all your source files and then combine them into a single output that can be used in a browser and based on this Benchmark it's pretty amazing how much faster things have gotten just since webpack 5 a couple years ago oh and another really cool thing is that bun has a sqlite database built directly into the runtime it's incredibly convenient to have a relational database without the need to install and configure a bunch of drivers another thing we need to talk about though is the button package manager that's up to 25 times faster than npm and it's actually a standalone tool that can be used in any node.js project today if you want to make things go faster right now replace npx with a command like bunks Cal say hello world which allows you to save a few precious milliseconds when saying hi to your mom which is important because you never know how much time you have left to do that this has been the code report thanks for watching and I will see you in the next one [Music]
Info
Channel: Fireship
Views: 972,820
Rating: undefined out of 5
Keywords: webdev, app development, lesson, tutorial
Id: dWqNgzZwVJQ
Channel Id: undefined
Length: 4min 29sec (269 seconds)
Published: Fri Sep 08 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.