How To Run NestJS with Bun [Simplest Guide] [Updated 2024]
Bun released its version 1.0!
If you go to the release notes, the most exciting part of Bun is...
It is ( almost ) completely compatible with ( almost ) all the existing Node.js ecosystem.
Actually, they made it so compatible, some compatibility issues in Node.js don't even exist for Bun.
The most notable is the module system, import
and require
keywords can exist in harmony without ever writing type: module
to your package.json!
Edit: 15 December 2023
This post became a rollercoaster, and it got a lot of attention. So, I feel responsible for keeping you guys updated.
The good news is that Bun now supports NestJS, out of the box.
The extended news is that some features are still missing. You might experience edge cases in some packages. Core packages should work well. There is a GitHub issue I linked below, you can follow it as a tracking place.
Edit: 12 September 2023
Well guys, that happened. Appearantly, I was tricked by the Bun commercial. Because, they advertised that Bun works with NestJS.
As I am excited about the Bun release, I jumped to the conclusions too quick. Appearantly, if you use bun start
it doesn't actually use Bun under the hood. Thankfully @jmcdo29
mentioned this issue in the Discord group of NestJS.
If anyone can't load the image, here is the explanation:
By the way,bun start
on anest new
project callsnest start
which uses thenest
CLI which has anode
shebang, so it's usingnode
, not bun.
- jmcdo29
The explanation below is not applicable currently.
How to Run NestJS with Bun
Okay, but how do you run NestJS with Bun?
Well, it is a problem of the past.
Simply:
bun start
If this doesn't work, install Bun first:
curl -fsSL https://bun.sh/install | bash
Don't you trust curl commands? Then you can use npm to install Bun:
npm install -g bun
NestJS or any other web framework popular enough is guaranteed to work with Bun.