My First Time with Bun - Why I Believe It Will Replace Node.js

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I finally tried bun for the first time and honestly I can't imagine ever going back to no. JS again for reference I've spent hours in the past just trying to set up a nodejs project to work with typescript es modules and have a hot reloading server but all of that stuff just works out of the box with bun node.js has been around for a long time now but maybe it's time for something new bun is a new JavaScript runtime to replace node.js but it's also a lot more it's a package manager it's a test Runner and it has automatic configurations for typescript and a hot reloading server and so much more I'll show you some of this Hands-On in a second in the project that I've been working on but first let's take a minute to talk about node and then we can understand more about what bun is and why it's so amazing so I've said a few times already that node and Bun are both JavaScript runtimes but what does that actually mean basically a runtime is an environment that allows you to run the JavaScript language so previous to node.js the only way we could use JavaScript was in the browser but node.js really revolutionized the L language of JavaScript by bringing it to the server and allowing us to do so much more than we ever had before with JavaScript specifically now one other thing to understand is a JavaScript engine so no. JS is a JavaScript runtime that is powered by the V8 JavaScript engine which is from Google Chrome so nodejs became the deao way to run JavaScript outside of the browser in a server for about 10 years and then a few years ago Dino was released created by the Creator original creator of node.js in an effort to kind of fix the mistakes that he made with no. JS Andino has been kind of up and down in popularity and excitement but most recently bun has come out and officially gone 1.0 which means it's really ready to use so let's talk a little bit more about bun it's amazing features and why I'm so excited about it and then at the end I'll show you Hands-On examples of what I'm talking about and the most recent project that I'm working on so while no JS uses the V8 engine from Google Chrome bun actually uses the JavaScript core engine which was built for or Safari so in some ways it doesn't really matter a whole lot to us using it because we don't really use the underlying engine directly but what we do care about is speed and Bun is really adamant about being faster than node.js and Dino as other runtimes to compare now the really cool thing about bun is that you don't have to make this big shift to a new runtime to be able to continue to work on what you've already been doing so bun is meant to be basically a drop in replacement for node.js which means you can bring basically all of your mpm packages over and you can continue to write JavaScript in the way that that you're used to from working with node.js and not really care about what's going on underneath the hood now this has certainly been true for me and I'll show you this in a minute in this project but I opened up uh or I created a new bun project I dropped in Express I wrote the same code I would for Express and node.js I dropped in molter for having file uploads and everything just worked I didn't have to do anything specific to make that work now an interesting thing about this is no. JS kind of originated the commonjs format foring doing import syntax we've since had esm and now we have difficulties in working with both esm modules and commonjs in bun those two work directly together and you can actually import using different types of import syntax in the same file which is really interesting now one thing I've already mentioned is the inclusion of typescript and this is huge I've spent a lot of time in the past just trying to figure out how to configure a no JS project to use typescript because let's be honest I don't create any project anymore with without using typescript it's become my deao way of working with JavaScript is to use typescript and if you look at Frameworks like nextjs or Astro or something like that they automatically support it but I've always struggled with coming up with a configuration in node.js to support typescript and that is out of the box with bun which means you don't have to worry about anything you can just start writing typescript and you're off and running now another thing that's really neat is bun already has a watch mode enabled for a live reloading server now in node.js for many years up until recently we use nodemon to be able to have a reloading a hot reloading server and what that meant was an extra package that we had to install also one thing to note in versions 18 something plus in node.js they have an experimental flag to do something similar but the bun version looks so much faster now I mentioned that bun is meant to be basically a dropin replacement for nodejs and that is mostly true almost all the apis that you're used to in node are available in bun I used the file system the other day I they have an HTTP server and websocket server working with files they also have a few extra things that are built in like working with testing which I haven't tried out yet but I'm excited about uh hashing a password which has always been a separate package that you had to install with node.js and then a bunch of other things so they have a lot of the main core libraries that you're used to from no node.js included already and then also some additional things to just make it easier for all the standard things that we do all the time one of the things that I was really impressed with was the mpm inst actually bun inst install uh process compared to npm install and it's one of those things where they talk about it being so much faster than pmpm and npm and yarn but you can't really grasp that I think until you use it so I didn't realize that I felt like npm was slow until now using bun and now it's like crazy noticeable how different it is working with bun versus node.js and that's really exciting because that means that's that much quicker that I can install packages and start writing code and getting to the thing that I'm building so just to sum up some of those bullet points the speed of bun is very noticeable the speed of installing packages the reloading server very noticeable the built-in configuration for typescript and for testing which I haven't tried yet and a reloading server that's amazing it's basically close to a one toone of being able to do anything in bun that I could in OJs so that's exciting it's officially 1.0 that's exciting it's amazing to see the progress that it's made so let's take a quick look at the project I've been working on and I can show you a few of these things right inside of that code so this is the project that I'm working on it's called split clip and this is basically a thing that I'm trying to build to help split videos in intelligent ways that I want using AI eventually and I'm going to be building this in public over the next couple of months you can expect more content from this and live streams Etc but this is bun and all I did was run a bun a nit it comes up with its lock file a package.json file which is fairly minimal and it's basically what you would expect so the first thing they give you is the index.ts file again typescript right out of the box and then you can see that I've installed packages that I can work with as well so I have the Zeta package that's the database that I'm working with which is really awesome it's built on top of postgress has a UI it has file storage now which I'm working with so we have the Zeta client uh is installed we have the molter package we have cores and then we're also able to import um FS the like promises version or the non- promises version just like you would in node.js and then use that again just like you would in node.js and that's really cool so all of this is a very familiar syntax all of it is very familiar for code I'm working with express the same way I've been doing for years and I love that it works out so so well that I don't have to go through a bunch of changes to take advantage of the benefits that bun gives me now if I were to run this I can run the bun run and then D- hot command and what that means is that's going to live reload the server anytime any of the files that are imported get changed and there's some technical details on their website about how they do that that makes this faster than uh nodon for example anyway it's super fast so if we look at uh the server is running I press save and it's running again like it it it almost is unnoticeable and that's really cool because I'm no longer like having to wait around for my server to start my server to restart Etc not that it was super long before but once you get into something that's faster it's just much more noticeable uh one of the things we can do is maybe uh remove the molter package that is done and then just to show you like a bun install of molter that thing happens super fast so it's really nice for that experience to be fast it's nice for type script to be built in it's nice for a lot of different things there's so many things I think that from a developer experience perspective no. JS was just lacking and Bun now takes care of for us from the start from the get-go so anyway I'm super excited about bun I imagine this is what I'm going to be using by default going forward with no JS or JavaScript on the server projects if I'm not using something like nextjs with serverless functions for example so this is kind of my go-to let me know what you think about bun is this something you're excited about are you going to try this out it's still early although it is 1.0 so it'll be curious I will be curious to see where this goes in the next uh you know year or however long so one of the things I do want to shout out is I have a newsletter so if you're interested in what I'm up to and some of my recent content and recent content from the Discord Community learn build teach that I run you can check out my newsletter at james.com newsletter love to stay in touch with you on a weekly basis but thank you for checking out the video and I'll catch you next time
Info
Channel: James Q Quick
Views: 13,877
Rating: undefined out of 5
Keywords: bun.sh, bun, bun runtime, javascript runtimes, javascript engines, bun vs node.js, bun replace nodejs, web development, javascript, bun typescript, nodejs typescript
Id: nM_NTPNhePs
Channel Id: undefined
Length: 8min 55sec (535 seconds)
Published: Fri Oct 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.