bun vs npm
Unanswered
Aviram posted this in #help-forum
AviramOP
I see some people use bun and some npm.
I looked in he bun website and it says it basiclly better than npm.
is there a reason to use npm instead of bun?
I looked in he bun website and it says it basiclly better than npm.
is there a reason to use npm instead of bun?
44 Replies
bun is a node replacement while npm is for packages
bun just includes features what npms has so it completely replaces npm
so its bun vs npm & node
for now i would say using npm & node is more stable while bun is still in development
it really depends on what project u build
bun is indeed faster than node tho
AviramOP
Alright, thank you
I'm just new to JS/TS
I want to build a nextjs website and I'm overwhelmed a bit
Nextjs isn't compatible with bun
running bun invokes node
AviramOP
ill stick to npm & node.js
wait, looks like it does support next
@@ts-ignore wait, looks like it does support next
AviramOP
yea, I tried doing
bun dev and it run my next js project@Aviram yea, I tried doing `bun dev` and it run my next js project
earlier it used to invoke node under the hood as nextjs used some node specific APIs
AviramOP
its so confusing when the backend and frontend is together and you can render on server or on client I don't understand that
@Aviram its so confusing when the backend and frontend is together and you can render on server or on client I don't understand that
Golden northern bumble bee
If you don't know why you need server side rendering, you can pretty much always render on the client if you put "use client" at the top of your files.
This is more similar to vanilla react
@Golden northern bumble bee If you don't know why you need server side rendering, you can pretty much always render on the client if you put "use client" at the top of your files.
AviramOP
but I want to know when and if I need that.
because there is a reason it exists.
because there is a reason it exists.
Golden northern bumble bee
Server side rendering takes away your ability to use client features like useState and useEffect, but in exchange you get to use server side features like importing data directly from the database instead of using a fetch call to get the data
that's interesting
Golden northern bumble bee
So for example, if you're using mongoose to fetch data, you can just mark your server component as async and await the response form the database before using that data in the component.
AviramOP
I need to find a tutorial which explains all that stuff
Golden northern bumble bee
It's kind of hard to wrap your head around. Took me a while.
AviramOP
I guess it will take practice
but I'll only learn it by building something
that's the best way I have learn my other programming languages/frameworks
Golden northern bumble bee
That's exactly how I learned. Luckily next.js is popular so there's a lot of resources out there
@Golden northern bumble bee So for example, if you're using mongoose to fetch data, you can just mark your server component as async and await the response form the database before using that data in the component.
Dutch Smoushond
yeah so the users won't see the loading screen
Golden northern bumble bee
They have a solution for that. read into the app router a little. You can pass it a loading file it will render until the server page is ready
AviramOP
that's cool, I'll try using that
@@ts-ignore earlier it used to invoke node under the hood as nextjs used some node specific APIs
It still does that (for now), unless you --bun or don't have node installed
But the bun runtime support of nextjs is decent now (no means perfect tho)
But the bun runtime support of nextjs is decent now (no means perfect tho)
@Aviram yea, I tried doing `bun dev` and it run my next js project
Sun bear
during development or if you are just building stuff for fun or learning purposes, you can use bun package manager as it installs packages much faster than npm, then when you are deploying via docker or something like that you can switch to npm & node or other stable runtimes
this gives you the best of DX during develoment and stability in production
@Sun bear during development or if you are just building stuff for fun or learning purposes, you can use bun package manager as it installs packages much faster than npm, then when you are deploying via docker or something like that you can switch to npm & node or other stable runtimes
Can I ask what is unstable with bun install, I'm genuinely interested as it is very stable now... the runtime is good but it's node compat with minor querks is issue
(Dealing with 2 pkg managers means no actual lockfike- and thus less stability)
(Dealing with 2 pkg managers means no actual lockfike- and thus less stability)
And as I said above, bun package manager doesn't force bun runtime
bun >>>> npm on every single measurable metric, so my answer to this question is no, there just isn't a reason to use npm instead of bun. the fact that the Dockerfile is one line longer in case of bun compared to npm is but a tiny disadvantage easily overcome by the significant DX gains from using bun.
and yea if you absolutely want to use npm at all cost, stick with it. do not use two pm at the same time.
@riský Can I ask what is unstable with bun install, I'm genuinely interested as it is very stable now... the runtime is good but it's node compat with minor querks is issue
(Dealing with 2 pkg managers means no actual lockfike- and thus less stability)
Sun bear
You are right, forget what I said above