How To Run NestJS with Bun [Simplest Guide] [Updated 2024]

You can run NestJS with Bun

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.

Bun v1.0.3 | Bun Blog
emitDecoratorMetadata, Nest.js support, better private registry support, bunx bugfix, console.log() depth 8 -> 2, silence .env loaded message, and many bugfixes

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

discord talk with jmcdo29 about bun support of nestjs

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 a nest new project calls nest start which uses the nest CLI which has a node shebang, so it's using node, 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.