Albert Putra Purnama • 2022-08-06
Some thoughts
For some reason, new Javascript runtimes pop out every year now. Last year was Deno, this year it's Bun.
For those who don't know what these are, you should check them out!
I think this post might be a long one. So here's a TLDR from Twitter.
I used starter Typescript template as the base of my project. Since it uses frameworks and database connectors that I need. Feel free to use other boilerplates that you want.
A couple of sort of important details:
I plan to use bun instead of NodeJS in projects using this template. Let me show you what I did.
I used the command npx typescript-express-starter "project name"
and selected TypeORM template.
Then I test if everything works well, spin up a database server if necessary, etc. Basically, I need to make sure that the yarn dev
command works well. Then we can replace it with bun
or deno
commands.
Successful cloning and setup
To use Bun in this project, all you need to do is run bun install
and then bun run src/server.ts
As of 0.1.16
, you should be getting:
Some error regarding to buffer
I'm not too sure what's causing this error, I suspect Buffer isn't really supported yet, that's why it's returning this error. You can see in Bun's roadmap that Buffer is not fully implemented yet.
Unfinished Buffer implementation
I haven't tried to resolve this bug until now, since there are a lot of things not supported yet (one of them is Express). However, I am well aware that bun install
can replace yarn
because of its speed.
You can replace any yarn
command with bun run
. And everything should still work flawlessly. Please note that using bun run
does not mean you're using bun on runtime, it simply runs whatever command you gave it to.
In our case, if you didn't change the project at all, you'll still be running nodemon
which uses NodeJS to run your server, You won't be seeing the perf increase Bun has promised!
I also tried to use Bun in Docker images only for installation purposes. A comment in github is helpful to get bun up and running in Docker, but it seems like it's not really possible yet (You'll get FileNotFound
error after bun install
) if you're still using NodeJS underneath.
You can see from Bun's roadmap that it's trying to make bun compatible with existing package managers, and implements all NodeJS APIs. Let's take a look at Deno now.
Right off the bat, you are faced with a completely different package system. In Deno, there's no more package.json
because everything is tracked by the import statement directly. Usually, these imports are tracked in ./deps.ts
stored in the root directory of the project.
The deps.ts
files just import and immediately export the dependencies. This file acts as the new package.json
. You can also use import maps instead of using deps.ts
I think they are interchangeable and you can also use both of them if you want.
Deno's biggest problem in my opinion is its developer experience moving from npm structured package to Deno's structure. To be honest, modifying import statements throughout the codebase is not fun at all.
Another huge problem that I see is that your dependencies need to be ESM compatible for them to be used in your Deno projects. And for some reason, they are hosted in deno.land/x
where they sometimes refer to the original repo, and sometimes a completely new repo that's supposed to clone the original.
Compare TypeORM's repository and TypeORM listed in deno's third party modules. They show completely different codebase, I think mostly because TypeORM does not support ESM out of the box. However, I can't really be 100% sure here.
I'm leaning more towards Bun for its ease of use (great install & usage experience in general). I think dev tools should make life easier by making the existing process so much easier while maintaining backward compatibility.
But to be honest, Bun still has a long way to go until it reaches the stable version. In my opinion, using NodeJS right now is still better than using Deno or Bun in their current state.
I believe the best plan for developers that are looking to use Bun is to start building the NodeJS app now while waiting for Bun to become stable. I'm sure you'll have an enjoyable time migrating from Node to Bun. Everything just works!
Suggest new blog topics down here!
Apurn.eth
Copyright © 2022 apurn.eth. All rights reserved.
Connect with me
Legal
Terms of Servicee
Privacy Policy
Made in Typedream